From: Ruben Kerkhof Date: Sat, 2 Apr 2016 13:35:59 +0000 (+0200) Subject: collectdmon: close fd when dup2 fails X-Git-Tag: collectd-5.6.0~368 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=4d7bc9c5bfc24bbd56edbb1daa87c76fedc858d0;p=collectd.git collectdmon: close fd when dup2 fails Fixed CID #73119 Fix a typo in the error message while we're at it. --- diff --git a/src/collectdmon.c b/src/collectdmon.c index 2c1d5897..13304f2a 100644 --- a/src/collectdmon.c +++ b/src/collectdmon.c @@ -156,21 +156,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; }