Attempt to open /dev/null before forking incase it would fail

This commit is contained in:
Aaron Jones 2016-08-21 00:32:34 +00:00
parent 0c433865d3
commit 0c23c0b1c5
No known key found for this signature in database
GPG key ID: EC6F86EE9CD840B5

View file

@ -225,6 +225,12 @@ make_daemon(void)
we need control over the parent after forking to print
the startup message -- Aaron */
if((nullfd = open("/dev/null", O_RDWR)) < 0)
{
perror("open /dev/null");
exit(EXIT_FAILURE);
}
if((pid = fork()) < 0)
{
perror("fork");
@ -238,12 +244,6 @@ make_daemon(void)
exit(EXIT_SUCCESS);
}
if((nullfd = open("/dev/null", O_RDWR)) < 0)
{
perror("open /dev/null");
exit(EXIT_FAILURE);
}
for(fdx = 0; fdx <= 2; fdx++)
if (fdx != nullfd)
(void) dup2(nullfd, fdx);