if we can't open /dev/null, you have much bigger issues to deal with

This commit is contained in:
Michael Jerris 2014-04-28 16:02:39 -04:00
parent 34c967707d
commit e7107f616f
1 changed files with 3 additions and 0 deletions

View File

@ -341,18 +341,21 @@ static void daemonize(int *fds)
} }
/* redirect std* to null */ /* redirect std* to null */
fd = open("/dev/null", O_RDONLY); fd = open("/dev/null", O_RDONLY);
switch_assert( fd >= 0 );
if (fd != 0) { if (fd != 0) {
dup2(fd, 0); dup2(fd, 0);
close(fd); close(fd);
} }
fd = open("/dev/null", O_WRONLY); fd = open("/dev/null", O_WRONLY);
switch_assert( fd >= 0 );
if (fd != 1) { if (fd != 1) {
dup2(fd, 1); dup2(fd, 1);
close(fd); close(fd);
} }
fd = open("/dev/null", O_WRONLY); fd = open("/dev/null", O_WRONLY);
switch_assert( fd >= 0 );
if (fd != 2) { if (fd != 2) {
dup2(fd, 2); dup2(fd, 2);
close(fd); close(fd);