diff --git a/src/collectd.c b/src/collectd.c
index 47745cb0c05929dd2fac3047ead5f0908dc5f31d..a1e15bf1e7ca52b674632b1308012c91297d2c00 100644 (file)
--- a/src/collectd.c
+++ b/src/collectd.c
/**
* collectd - src/collectd.c
/**
* collectd - src/collectd.c
- * Copyright (C) 2005 Florian octo Forster
+ * Copyright (C) 2005,2006 Florian octo Forster
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
#include "plugin.h"
#include "configfile.h"
#include "plugin.h"
#include "configfile.h"
-#include "ping.h"
-
static int loop = 0;
#if HAVE_LIBKSTAT
static int loop = 0;
#if HAVE_LIBKSTAT
* exported variables
*/
time_t curtime;
* exported variables
*/
time_t curtime;
-
-#if HAVE_LIBRRD
-int operating_mode;
-#endif
+int operating_mode;
static void sigIntHandler (int signal)
{
static void sigIntHandler (int signal)
{
" General:\n"
" -C <file> Configuration file.\n"
" Default: "CONFIGFILE"\n"
" General:\n"
" -C <file> Configuration file.\n"
" Default: "CONFIGFILE"\n"
+ " -P <file> PID-file.\n"
+ " Default: "PIDFILE"\n"
#if COLLECT_DAEMON
" -f Don't fork to the background.\n"
#endif
#if COLLECT_DAEMON
" -f Don't fork to the background.\n"
#endif
#endif
" Step "COLLECTD_STEP" seconds\n"
" Heartbeat "COLLECTD_HEARTBEAT" seconds\n"
#endif
" Step "COLLECTD_STEP" seconds\n"
" Heartbeat "COLLECTD_HEARTBEAT" seconds\n"
- "\n"PACKAGE" "VERSION", http://verplant.org/collectd/\n"
+ "\n"PACKAGE" "VERSION", http://collectd.org/\n"
"by Florian octo Forster <octo@verplant.org>\n"
"for contributions see `AUTHORS'\n");
exit (0);
"by Florian octo Forster <octo@verplant.org>\n"
"for contributions see `AUTHORS'\n");
exit (0);
static int start_client (void)
{
static int start_client (void)
{
- int sleepingtime;
int step;
int step;
+ struct timeval tv_now;
+ struct timeval tv_next;
+ struct timespec ts_wait;
+
step = atoi (COLLECTD_STEP);
if (step <= 0)
step = 10;
step = atoi (COLLECTD_STEP);
if (step <= 0)
step = 10;
while (loop == 0)
{
while (loop == 0)
{
- curtime = time (NULL);
+ if (gettimeofday (&tv_next, NULL) < 0)
+ {
+ syslog (LOG_ERR, "gettimeofday failed: %s", strerror (errno));
+ return (-1);
+ }
+ tv_next.tv_sec += step;
+
#if HAVE_LIBKSTAT
update_kstat ();
#endif
#if HAVE_LIBKSTAT
update_kstat ();
#endif
- plugin_read_all ();
+ /* `curtime' is used by many (all?) plugins as the
+ * data-sample-time passed to RRDTool */
+ curtime = time (NULL);
+
+ /* Issue all plugins */
+ plugin_read_all (&loop);
- sleepingtime = step;
- while (sleepingtime != 0)
+ if (gettimeofday (&tv_now, NULL) < 0)
{
{
- if (loop != 0)
+ syslog (LOG_ERR, "gettimeofday failed: %s", strerror (errno));
+ return (-1);
+ }
+
+ if (timeval_sub_timespec (&tv_next, &tv_now, &ts_wait) != 0)
+ {
+ syslog (LOG_WARNING, "Not sleeping because `timeval_sub_timespec' returned non-zero!");
+ continue;
+ }
+
+ while ((loop == 0) && (nanosleep (&ts_wait, &ts_wait) == -1))
+ {
+ if (errno != EINTR)
+ {
+ syslog (LOG_ERR, "nanosleep failed: %s", strerror (errno));
break;
break;
- sleepingtime = sleep (sleepingtime);
+ }
}
}
}
}
return (1);
}
return (1);
}
- fprintf (fh, "%d\n", getpid());
+ fprintf (fh, "%i\n", (int) getpid ());
fclose(fh);
return (0);
fclose(fh);
return (0);
char *configfile = CONFIGFILE;
#if COLLECT_DAEMON
struct sigaction sigChldAction;
char *configfile = CONFIGFILE;
#if COLLECT_DAEMON
struct sigaction sigChldAction;
- char *pidfile = PIDFILE;
+ char *pidfile = NULL;
pid_t pid;
int daemonize = 1;
#endif
pid_t pid;
int daemonize = 1;
#endif
#if HAVE_LIBRRD
operating_mode = MODE_LOCAL;
#if HAVE_LIBRRD
operating_mode = MODE_LOCAL;
+#else
+ operating_mode = MODE_CLIENT;
#endif
/* open syslog */
#endif
/* open syslog */
c = getopt (argc, argv, "hC:"
#if COLLECT_DAEMON
c = getopt (argc, argv, "hC:"
#if COLLECT_DAEMON
- "f"
+ "fP:"
#endif
);
#endif
);
configfile = optarg;
break;
#if COLLECT_DAEMON
configfile = optarg;
break;
#if COLLECT_DAEMON
+ case 'P':
+ pidfile = optarg;
+ break;
case 'f':
daemonize = 0;
break;
case 'f':
daemonize = 0;
break;
sigChldAction.sa_handler = SIG_IGN;
sigaction (SIGCHLD, &sigChldAction, NULL);
sigChldAction.sa_handler = SIG_IGN;
sigaction (SIGCHLD, &sigChldAction, NULL);
- if ((pidfile = cf_get_option ("PIDFile", PIDFILE)) == NULL)
+ if ((pidfile == NULL)
+ && ((pidfile = cf_get_option ("PIDFile", PIDFILE)) == NULL))
{
fprintf (stderr, "Cannot obtain pidfile. This shoud not happen. Ever.");
return (1);
{
fprintf (stderr, "Cannot obtain pidfile. This shoud not happen. Ever.");
return (1);
#if HAVE_LIBRRD
if (operating_mode == MODE_SERVER)
start_server ();
#if HAVE_LIBRRD
if (operating_mode == MODE_SERVER)
start_server ();
- else /* if (operating_mode == MODE_CLIENT || operating_mode == MODE_LOCAL) */
+ else /* if (operating_mode == MODE_CLIENT || operating_mode == MODE_LOCAL || operating_mode == MODE_LOG) */
#endif
start_client ();
#endif
start_client ();
+ plugin_shutdown_all ();
+
#if COLLECT_DEBUG
if (logfile != NULL)
DBG_STOPFILE("debug file closed.");
#if COLLECT_DEBUG
if (logfile != NULL)
DBG_STOPFILE("debug file closed.");