Merge branch 'collectd-5.5'
[collectd.git] / src / collectdmon.c
index 6c50cf1..f2798ee 100644 (file)
@@ -119,6 +119,7 @@ static int pidfile_delete (void)
 static int daemonize (void)
 {
        struct rlimit rl;
+       int status;
 
        pid_t pid = 0;
        int   i   = 0;
@@ -153,21 +154,24 @@ static int daemonize (void)
                close (i);
 
        errno = 0;
-       if (open ("/dev/null", O_RDWR) != 0) {
+       status = open ("/dev/null", O_RDWR);
+       if (status != 0) {
                syslog (LOG_ERR, "Error: couldn't connect STDIN to /dev/null: %s",
                                strerror (errno));
                return -1;
        }
 
        errno = 0;
-       if (dup (0) != 1) {
+       status = dup (0);
+       if (status != 1) {
                syslog (LOG_ERR, "Error: couldn't connect STDOUT to /dev/null: %s",
                                strerror (errno));
                return -1;
        }
 
        errno = 0;
-       if (dup (0) != 2) {
+       status = dup (0);
+       if (status != 2) {
                syslog (LOG_ERR, "Error: couldn't connect STDERR to /dev/null: %s",
                                strerror (errno));
                return -1;
@@ -317,7 +321,10 @@ int main (int argc, char **argv)
        openlog ("collectdmon", LOG_CONS | LOG_PID, LOG_DAEMON);
 
        if (-1 == daemonize ())
+       {
+               free (collectd_argv);
                return 1;
+       }
 
        sa.sa_handler = sig_int_term_handler;
        sa.sa_flags   = 0;
@@ -325,11 +332,13 @@ int main (int argc, char **argv)
 
        if (0 != sigaction (SIGINT, &sa, NULL)) {
                syslog (LOG_ERR, "Error: sigaction() failed: %s", strerror (errno));
+               free (collectd_argv);
                return 1;
        }
 
        if (0 != sigaction (SIGTERM, &sa, NULL)) {
                syslog (LOG_ERR, "Error: sigaction() failed: %s", strerror (errno));
+               free (collectd_argv);
                return 1;
        }
 
@@ -337,6 +346,7 @@ int main (int argc, char **argv)
 
        if (0 != sigaction (SIGHUP, &sa, NULL)) {
                syslog (LOG_ERR, "Error: sigaction() failed: %s", strerror (errno));
+               free (collectd_argv);
                return 1;
        }