X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fdaemon%2Fcollectd.c;h=3a6fe1e962abb033a06ce00d7e78399efa6462b1;hb=aa3811995bfae69f0d1a0f897acfa4a9a4c0138a;hp=a72ff35f2fc21ec042e809d64967100f35f5a9fd;hpb=6600bd1351bf81e0831e7ad95ee37a7b28cbdf94;p=collectd.git diff --git a/src/daemon/collectd.c b/src/daemon/collectd.c index a72ff35f..3a6fe1e9 100644 --- a/src/daemon/collectd.c +++ b/src/daemon/collectd.c @@ -35,8 +35,6 @@ #include #include -#include - #if HAVE_LOCALE_H # include #endif @@ -54,7 +52,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; @@ -100,7 +97,6 @@ static int init_hostname (void) { const char *str; - struct addrinfo ai_hints; struct addrinfo *ai_list; struct addrinfo *ai_ptr; int status; @@ -123,8 +119,9 @@ static int init_hostname (void) if (IS_FALSE (str)) return (0); - memset (&ai_hints, '\0', sizeof (ai_hints)); - ai_hints.ai_flags = AI_CANONNAME; + struct addrinfo ai_hints = { + .ai_flags = AI_CANONNAME + }; status = getaddrinfo (hostname_g, NULL, &ai_hints, &ai_list); if (status != 0) @@ -444,7 +441,7 @@ static int notify_systemd (void) { int fd; const char *notifysocket; - struct sockaddr_un su; + struct sockaddr_un su = { 0 }; size_t su_size; char buffer[] = "READY=1\n"; @@ -474,7 +471,6 @@ static int notify_systemd (void) return 0; } - memset (&su, 0, sizeof (su)); su.sun_family = AF_UNIX; if (notifysocket[0] != '@') { @@ -512,16 +508,11 @@ static int notify_systemd (void) int main (int argc, char **argv) { - struct sigaction sig_int_action; - struct sigaction sig_term_action; - struct sigaction sig_usr1_action; - struct sigaction sig_pipe_action; const char *configfile = CONFIGFILE; int test_config = 0; int test_readall = 0; const char *basedir; #if COLLECT_DAEMON - struct sigaction sig_chld_action; pid_t pid; int daemonize = 1; #endif @@ -551,15 +542,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; @@ -622,8 +612,10 @@ int main (int argc, char **argv) /* * fork off child */ - memset (&sig_chld_action, '\0', sizeof (sig_chld_action)); - sig_chld_action.sa_handler = SIG_IGN; + struct sigaction sig_chld_action = { + .sa_handler = SIG_IGN + }; + sigaction (SIGCHLD, &sig_chld_action, NULL); /* @@ -689,15 +681,19 @@ int main (int argc, char **argv) } /* if (daemonize) */ #endif /* COLLECT_DAEMON */ - memset (&sig_pipe_action, '\0', sizeof (sig_pipe_action)); - sig_pipe_action.sa_handler = SIG_IGN; + struct sigaction sig_pipe_action = { + .sa_handler = SIG_IGN + }; + sigaction (SIGPIPE, &sig_pipe_action, NULL); /* * install signal handlers */ - memset (&sig_int_action, '\0', sizeof (sig_int_action)); - sig_int_action.sa_handler = sig_int_handler; + struct sigaction sig_int_action = { + .sa_handler = sig_int_handler + }; + if (0 != sigaction (SIGINT, &sig_int_action, NULL)) { char errbuf[1024]; ERROR ("Error: Failed to install a signal handler for signal INT: %s", @@ -705,8 +701,10 @@ int main (int argc, char **argv) return (1); } - memset (&sig_term_action, '\0', sizeof (sig_term_action)); - sig_term_action.sa_handler = sig_term_handler; + struct sigaction sig_term_action = { + .sa_handler = sig_term_handler + }; + if (0 != sigaction (SIGTERM, &sig_term_action, NULL)) { char errbuf[1024]; ERROR ("Error: Failed to install a signal handler for signal TERM: %s", @@ -714,8 +712,10 @@ int main (int argc, char **argv) return (1); } - memset (&sig_usr1_action, '\0', sizeof (sig_usr1_action)); - sig_usr1_action.sa_handler = sig_usr1_handler; + struct sigaction sig_usr1_action = { + .sa_handler = sig_usr1_handler + }; + if (0 != sigaction (SIGUSR1, &sig_usr1_action, NULL)) { char errbuf[1024]; ERROR ("Error: Failed to install a signal handler for signal USR1: %s",