Check return code from open()

This commit is contained in:
Simon Kelley
2016-03-01 16:19:23 +00:00
parent aa300f7167
commit f7cf749943

View File

@@ -561,10 +561,13 @@ int main (int argc, char **argv)
{ {
/* open stdout etc to /dev/null */ /* open stdout etc to /dev/null */
int nullfd = open("/dev/null", O_RDWR); int nullfd = open("/dev/null", O_RDWR);
dup2(nullfd, STDOUT_FILENO); if (nullfd != -1)
dup2(nullfd, STDERR_FILENO); {
dup2(nullfd, STDIN_FILENO); dup2(nullfd, STDOUT_FILENO);
close(nullfd); dup2(nullfd, STDERR_FILENO);
dup2(nullfd, STDIN_FILENO);
close(nullfd);
}
} }
/* if we are to run scripts, we need to fork a helper before dropping root. */ /* if we are to run scripts, we need to fork a helper before dropping root. */