diff --git a/src/usr.sbin/ntpd/ntp_dns.c b/src/usr.sbin/ntpd/ntp_dns.c index f00ef1d2..72cf19be 100644 --- a/src/usr.sbin/ntpd/ntp_dns.c +++ b/src/usr.sbin/ntpd/ntp_dns.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ntp_dns.c,v 1.13 2015/10/10 20:10:14 deraadt Exp $ */ +/* $OpenBSD: ntp_dns.c,v 1.14 2015/10/25 10:52:48 deraadt Exp $ */ /* * Copyright (c) 2003-2008 Henning Brauer @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -52,7 +53,7 @@ ntp_dns(int pipe_ntp[2], struct ntpd_conf *nconf, struct passwd *pw) { pid_t pid; struct pollfd pfd[1]; - int nfds; + int nfds, nullfd; switch (pid = fork()) { case -1: @@ -74,6 +75,16 @@ ntp_dns(int pipe_ntp[2], struct ntpd_conf *nconf, struct passwd *pw) fatal("setsid"); } + if ((nullfd = open("/dev/null", O_RDWR, 0)) == -1) + fatal(NULL); + + if (!nconf->debug) { + dup2(nullfd, STDIN_FILENO); + dup2(nullfd, STDOUT_FILENO); + dup2(nullfd, STDERR_FILENO); + } + close(nullfd); + setproctitle("dns engine"); close(pipe_ntp[0]);