X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fdaemon%2Fcollectd.c;h=ce4922d602ec2d5aa4bbd4f81a3e9856b3e995a4;hp=a745d7d1ad367c93bf9d823f78298b68e0ccba93;hb=1737d01e6d25487852d0da2e45088e11115e52a9;hpb=ccc4feb9576f520596508418f404beb000fde1aa diff --git a/src/daemon/collectd.c b/src/daemon/collectd.c index a745d7d1..ce4922d6 100644 --- a/src/daemon/collectd.c +++ b/src/daemon/collectd.c @@ -54,7 +54,6 @@ */ char hostname_g[DATA_MAX_NAME_LEN]; cdtime_t interval_g; -int pidfile_from_cli = 0; int timeout_g; #if HAVE_LIBKSTAT kstat_ctl_t *kc; @@ -196,7 +195,7 @@ 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); } @@ -269,6 +268,7 @@ static void update_kstat (void) /* TODO * Remove all settings but `-f' and `-C' */ +__attribute__((noreturn)) static void exit_usage (int status) { printf ("Usage: "PACKAGE_NAME" [OPTIONS]\n\n" @@ -331,9 +331,7 @@ static int do_init (void) } #endif - plugin_init_all (); - - return (0); + return plugin_init_all (); } /* int do_init () */ @@ -387,8 +385,7 @@ static int do_loop (void) static int do_shutdown (void) { - plugin_shutdown_all (); - return (0); + return plugin_shutdown_all (); } /* int do_shutdown */ #if COLLECT_DAEMON @@ -518,7 +515,7 @@ int main (int argc, char **argv) struct sigaction sig_term_action; struct sigaction sig_usr1_action; struct sigaction sig_pipe_action; - char *configfile = CONFIGFILE; + const char *configfile = CONFIGFILE; int test_config = 0; int test_readall = 0; const char *basedir; @@ -553,15 +550,14 @@ int main (int argc, char **argv) break; case 'T': test_readall = 1; - global_option_set ("ReadThreads", "-1"); + global_option_set ("ReadThreads", "-1", 1); #if COLLECT_DAEMON daemonize = 0; #endif /* COLLECT_DAEMON */ break; #if COLLECT_DAEMON case 'P': - global_option_set ("PIDFile", optarg); - pidfile_from_cli = 1; + global_option_set ("PIDFile", optarg, 1); break; case 'f': daemonize = 0; @@ -728,12 +724,19 @@ int main (int argc, char **argv) /* * run the actual loops */ - do_init (); + if (do_init () != 0) + { + ERROR ("Error: one or more plugin init callbacks failed."); + exit_status = 1; + } if (test_readall) { if (plugin_read_all_once () != 0) + { + ERROR ("Error: one or more plugin read callbacks failed."); exit_status = 1; + } } else { @@ -744,7 +747,11 @@ int main (int argc, char **argv) /* close syslog */ INFO ("Exiting normally."); - do_shutdown (); + if (do_shutdown () != 0) + { + ERROR ("Error: one or more plugin shutdown callbacks failed."); + exit_status = 1; + } #if COLLECT_DAEMON if (daemonize)