Rewrite SetupLogging to not leak the fd. Thanks to Steve Grubb for advice on this.

remotes/origin/master-1.1.x
Victor Julien 14 years ago
parent ba9fb53461
commit b5e17ec1d8

@ -79,18 +79,23 @@ static void WaitForChild (pid_t pid) {
* \brief Close stdin, stdout, stderr.Redirect logging info to syslog * \brief Close stdin, stdout, stderr.Redirect logging info to syslog
* *
*/ */
static void SetupLogging () { static void SetupLogging (void) {
int fd0, fd1, fd2;
/* Close stdin, stdout, stderr */ /* Close stdin, stdout, stderr */
close(0); close(0);
close(1); close(1);
close(2); close(2);
/* Redirect stdin, stdout, stderr to /dev/null */ /* Redirect stdin, stdout, stderr to /dev/null */
fd0 = open("/dev/null", O_RDWR); int fd = open("/dev/null", O_RDWR);
fd1 = dup(0); if (fd < 0)
fd2 = dup(0); return;
if (dup2(fd, 0) < 0)
return;
if (dup2(fd, 1) < 0)
return;
if (dup2(fd, 2) < 0)
return;
close(fd);
} }
/** /**

Loading…
Cancel
Save