diff --git a/src/usr.sbin/ntpd/ntp.c b/src/usr.sbin/ntpd/ntp.c index 9c03747e..d3cb8ca4 100644 --- a/src/usr.sbin/ntpd/ntp.c +++ b/src/usr.sbin/ntpd/ntp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ntp.c,v 1.143 2016/09/14 13:20:16 rzalamena Exp $ */ +/* $OpenBSD: ntp.c,v 1.144 2016/09/26 16:55:02 rzalamena Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -425,14 +425,9 @@ ntp_dispatch_imsg(void) struct imsg imsg; int n; - if ((n = imsg_read(ibuf_main)) == -1 && errno != EAGAIN) + if (((n = imsg_read(ibuf_main)) == -1 && errno != EAGAIN) || n == 0) return (-1); - if (n == 0) { /* connection closed */ - log_warnx("ntp_dispatch_imsg in ntp engine: pipe closed"); - return (-1); - } - for (;;) { if ((n = imsg_get(ibuf_main, &imsg)) == -1) return (-1); @@ -477,14 +472,9 @@ ntp_dispatch_imsg_dns(void) struct ntp_addr *h; int n; - if ((n = imsg_read(ibuf_dns)) == -1) + if (((n = imsg_read(ibuf_dns)) == -1 && errno != EAGAIN) || n == 0) return (-1); - if (n == 0) { /* connection closed */ - log_warnx("ntp_dispatch_imsg_dns in ntp engine: pipe closed"); - return (-1); - } - for (;;) { if ((n = imsg_get(ibuf_dns, &imsg)) == -1) return (-1); diff --git a/src/usr.sbin/ntpd/ntp_dns.c b/src/usr.sbin/ntpd/ntp_dns.c index a8dcf98c..b9611c48 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.18 2016/09/14 13:20:16 rzalamena Exp $ */ +/* $OpenBSD: ntp_dns.c,v 1.19 2016/09/26 16:55:02 rzalamena Exp $ */ /* * Copyright (c) 2003-2008 Henning Brauer @@ -135,14 +135,9 @@ dns_dispatch_imsg(void) struct ibuf *buf; const char *str; - if ((n = imsg_read(ibuf_dns)) == -1 && errno != EAGAIN) + if (((n = imsg_read(ibuf_dns)) == -1 && errno != EAGAIN) || n == 0) return (-1); - if (n == 0) { /* connection closed */ - log_warnx("dispatch_imsg in main: pipe closed"); - return (-1); - } - for (;;) { if ((n = imsg_get(ibuf_dns, &imsg)) == -1) return (-1); diff --git a/src/usr.sbin/ntpd/ntpd.c b/src/usr.sbin/ntpd/ntpd.c index 2df47e84..3be7306b 100644 --- a/src/usr.sbin/ntpd/ntpd.c +++ b/src/usr.sbin/ntpd/ntpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ntpd.c,v 1.109 2016/09/14 13:20:16 rzalamena Exp $ */ +/* $OpenBSD: ntpd.c,v 1.110 2016/09/26 16:55:02 rzalamena Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -41,7 +41,7 @@ void sighdlr(int); __dead void usage(void); int main(int, char *[]); -int check_child(pid_t, const char *); +void check_child(void); int dispatch_imsg(struct ntpd_conf *, const char *, uid_t, gid_t); int dispatch_imsg_ctl(struct ntpd_conf *); void reset_adjtime(void); @@ -110,7 +110,7 @@ main(int argc, char *argv[]) { struct ntpd_conf lconf; struct pollfd *pfd = NULL; - pid_t chld_pid = 0, pid; + pid_t pid; const char *conffile; int ch, nfds, i, j; int pipe_chld[2]; @@ -227,7 +227,7 @@ main(int argc, char *argv[]) signal(SIGCHLD, sighdlr); /* fork child process */ - chld_pid = start_child(NTP_PROC_NAME, pipe_chld[1], argc0, argv0); + start_child(NTP_PROC_NAME, pipe_chld[1], argc0, argv0); log_procinit("[priv]"); readfreq(); @@ -315,19 +315,15 @@ main(int argc, char *argv[]) } if (sigchld) { - if (check_child(chld_pid, "child")) { - quit = 1; - chld_pid = 0; - } + check_child(); sigchld = 0; } - } signal(SIGCHLD, SIG_DFL); - if (chld_pid) - kill(chld_pid, SIGTERM); + /* Close socket and start shutdown. */ + close(ibuf->fd); do { if ((pid = wait(NULL)) == -1 && @@ -341,36 +337,19 @@ main(int argc, char *argv[]) return (0); } -int -check_child(pid_t chld_pid, const char *pname) +void +check_child(void) { - int status, sig; - char *signame; + int status; pid_t pid; do { pid = waitpid(WAIT_ANY, &status, WNOHANG); - if (pid <= 0) { + if (pid <= 0) continue; - } else if (pid == chld_pid) { - if (WIFEXITED(status)) { - log_warnx("Lost child: %s exited", pname); - return (1); - } - if (WIFSIGNALED(status)) { - sig = WTERMSIG(status); - signame = strsignal(sig) ? - strsignal(sig) : "unknown"; - log_warnx("Lost child: %s terminated; " - "signal %d (%s)", pname, sig, signame); - return (1); - } - } else { - priv_constraint_check_child(pid, status); - } - } while (pid > 0 || (pid == -1 && errno == EINTR)); - return (0); + priv_constraint_check_child(pid, status); + } while (pid > 0 || (pid == -1 && errno == EINTR)); } int @@ -381,14 +360,9 @@ dispatch_imsg(struct ntpd_conf *lconf, const char *pw_dir, int n; double d; - if ((n = imsg_read(ibuf)) == -1 && errno != EAGAIN) + if (((n = imsg_read(ibuf)) == -1 && errno != EAGAIN) || n == 0) return (-1); - if (n == 0) { /* connection closed */ - log_warnx("dispatch_imsg in main: pipe closed"); - return (-1); - } - for (;;) { if ((n = imsg_get(ibuf, &imsg)) == -1) return (-1);