From f7cf7499435a5fa8c2835abdd70ca816074175a4 Mon Sep 17 00:00:00 2001 From: Simon Kelley Date: Tue, 1 Mar 2016 16:19:23 +0000 Subject: [PATCH] Check return code from open() --- src/dnsmasq.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/dnsmasq.c b/src/dnsmasq.c index 96aa780..045ec53 100644 --- a/src/dnsmasq.c +++ b/src/dnsmasq.c @@ -561,10 +561,13 @@ int main (int argc, char **argv) { /* open stdout etc to /dev/null */ int nullfd = open("/dev/null", O_RDWR); - dup2(nullfd, STDOUT_FILENO); - dup2(nullfd, STDERR_FILENO); - dup2(nullfd, STDIN_FILENO); - close(nullfd); + if (nullfd != -1) + { + dup2(nullfd, STDOUT_FILENO); + 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. */