From 81a717e58a8e82f0067ac5936971676bb7e811b9 Mon Sep 17 00:00:00 2001 From: henning <> Date: Fri, 28 Jan 2005 12:32:24 +0000 Subject: [PATCH] fatal() if daemon() fails, Alexander von Gernler --- src/usr.sbin/ntpd/ntpd.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/usr.sbin/ntpd/ntpd.c b/src/usr.sbin/ntpd/ntpd.c index 02247970..086f0883 100644 --- a/src/usr.sbin/ntpd/ntpd.c +++ b/src/usr.sbin/ntpd/ntpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ntpd.c,v 1.27 2004/12/22 16:04:11 henning Exp $ */ +/* $OpenBSD: ntpd.c,v 1.28 2005/01/28 12:32:24 henning Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -128,14 +128,15 @@ main(int argc, char *argv[]) if (!conf.settime) { log_init(conf.debug); if (!conf.debug) - daemon(1, 0); + if (daemon(1, 0)) + fatal("daemon"); } else timeout = 15 * 1000; if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_chld) == -1) fatal("socketpair"); - /* fork children */ + /* fork child process */ chld_pid = ntp_main(pipe_chld, &conf); setproctitle("[priv]"); @@ -170,7 +171,8 @@ main(int argc, char *argv[]) timeout = INFTIM; log_init(conf.debug); if (!conf.debug) - daemon(1, 0); + if (daemon(1, 0)) + fatal("daemon"); } if (nfds > 0 && (pfd[PFD_PIPE].revents & POLLOUT)) @@ -274,7 +276,8 @@ dispatch_imsg(struct ntpd_conf *conf) /* daemonize now */ log_init(conf->debug); if (!conf->debug) - daemon(1, 0); + if (daemon(1, 0)) + fatal("daemon"); conf->settime = 0; break; case IMSG_HOST_DNS: