X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fcollectd.c;h=1ccc1c08e1eca87d4975351d1764fe2116c38031;hb=8d8c82f9537feb8f15f049f3b1c071eaf2f5e2a5;hp=ceb184b012879d475e90f66108ac732ae2a193b3;hpb=1126617bebe569dffe6b7a5d3f0c400134b41d65;p=collectd.git diff --git a/src/collectd.c b/src/collectd.c index ceb184b0..1ccc1c08 100644 --- a/src/collectd.c +++ b/src/collectd.c @@ -118,7 +118,7 @@ static int init_hostname (void) ERROR ("Looking up \"%s\" failed. You have set the " "\"FQDNLookup\" option, but I cannot resolve " "my hostname to a fully qualified domain " - "name. Please fix you network " + "name. Please fix the network " "configuration.", hostname_g); return (-1); } @@ -138,28 +138,10 @@ static int init_hostname (void) static int init_global_variables (void) { - const char *str; - - str = global_option_get ("Interval"); - if (str == NULL) - { - interval_g = TIME_T_TO_CDTIME_T (10); - } - else - { - double tmp; + char const *str; - tmp = atof (str); - if (tmp <= 0.0) - { - fprintf (stderr, "Cannot set the interval to a " - "correct value.\n" - "Please check your settings.\n"); - return (-1); - } - - interval_g = DOUBLE_TO_CDTIME_T (tmp); - } + interval_g = cf_get_default_interval (); + assert (interval_g > 0); DEBUG ("interval_g = %.3f;", CDTIME_T_TO_DOUBLE (interval_g)); str = global_option_get ("Timeout"); @@ -200,8 +182,10 @@ static int change_basedir (const char *orig_dir) while ((dirlen > 0) && (dir[dirlen - 1] == '/')) dir[--dirlen] = '\0'; - if (dirlen <= 0) + if (dirlen <= 0) { + free (dir); return (-1); + } status = chdir (dir); if (status == 0) @@ -327,9 +311,10 @@ static int do_init (void) static int do_loop (void) { + cdtime_t interval = cf_get_default_interval (); cdtime_t wait_until; - wait_until = cdtime () + interval_g; + wait_until = cdtime () + interval; while (loop == 0) { @@ -349,12 +334,12 @@ static int do_loop (void) WARNING ("Not sleeping because the next interval is " "%.3f seconds in the past!", CDTIME_T_TO_DOUBLE (now - wait_until)); - wait_until = now + interval_g; + wait_until = now + interval; continue; } CDTIME_T_TO_TIMESPEC (wait_until - now, &ts_wait); - wait_until = wait_until + interval_g; + wait_until = wait_until + interval; while ((loop == 0) && (nanosleep (&ts_wait, &ts_wait) != 0)) { @@ -401,8 +386,9 @@ static int pidfile_create (void) static int pidfile_remove (void) { const char *file = global_option_get ("PIDFile"); + if (file == NULL) + return 0; - DEBUG ("unlink (%s)", (file != NULL) ? file : ""); return (unlink (file)); } /* static int pidfile_remove (const char *file) */ #endif /* COLLECT_DAEMON */ @@ -472,6 +458,8 @@ int main (int argc, char **argv) if (optind < argc) exit_usage (1); + plugin_init_ctx (); + /* * Read options from the config file, the environment and the command * line (in that order, with later options overwriting previous ones in