X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fcollectdmon.c;h=61daa58c6ba1f07a4fbfa3716125b3fcb0be73b2;hb=41288c6a9ed050b41ad47184aa1b53668c3588cc;hp=65271ddd3f424db9c3050979de59e70b328f7483;hpb=6286127470b83578c2889db546cfa32cb0fe0147;p=collectd.git diff --git a/src/collectdmon.c b/src/collectdmon.c index 65271ddd..61daa58c 100644 --- a/src/collectdmon.c +++ b/src/collectdmon.c @@ -55,6 +55,14 @@ #include +#ifndef PREFIX +# define PREFIX "/opt/" PACKAGE_NAME +#endif + +#ifndef LOCALSTATEDIR +# define LOCALSTATEDIR PREFIX "/var" +#endif + #ifndef COLLECTDMON_PIDFILE # define COLLECTDMON_PIDFILE LOCALSTATEDIR"/run/collectdmon.pid" #endif /* ! COLLECTDMON_PIDFILE */ @@ -66,10 +74,11 @@ static int loop = 0; static int restart = 0; -static char *pidfile = NULL; -static pid_t collectd_pid = 0; +static const char *pidfile = NULL; +static pid_t collectd_pid = 0; -static void exit_usage (char *name) +__attribute__((noreturn)) +static void exit_usage (const char *name) { printf ("Usage: %s [-- ]\n" @@ -155,21 +164,24 @@ static int daemonize (void) dev_null = open ("/dev/null", O_RDWR); if (dev_null == -1) { - syslog (LOG_ERR, "Error: couldn't failed to open /dev/null: %s", strerror (errno)); + syslog (LOG_ERR, "Error: couldn't open /dev/null: %s", strerror (errno)); return -1; } if (dup2 (dev_null, STDIN_FILENO) == -1) { + close (dev_null); syslog (LOG_ERR, "Error: couldn't connect STDIN to /dev/null: %s", strerror (errno)); return -1; } if (dup2 (dev_null, STDOUT_FILENO) == -1) { + close (dev_null); syslog (LOG_ERR, "Error: couldn't connect STDOUT to /dev/null: %s", strerror (errno)); return -1; } if (dup2 (dev_null, STDERR_FILENO) == -1) { + close (dev_null); syslog (LOG_ERR, "Error: couldn't connect STDERR to /dev/null: %s", strerror (errno)); return -1; }