summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrzalamena <rzalamena@openbsd.org>2016-09-26 16:55:02 +0000
committerrzalamena <rzalamena@openbsd.org>2016-09-26 16:55:02 +0000
commit785412490baa026cafb885e29ae870c93c9bbbb0 (patch)
treeb3b20ec3a2700cbe51d6edca6df9dc8da4ea6b7f
parentRegen (diff)
downloadwireguard-openbsd-785412490baa026cafb885e29ae870c93c9bbbb0.tar.xz
wireguard-openbsd-785412490baa026cafb885e29ae870c93c9bbbb0.zip
Teach ntpd(8) how to use socket status to shutdown the daemon. While at
it, remove some verbose shutdown messages that we had before with pipe close. ok reyk@
-rw-r--r--usr.sbin/ntpd/ntp.c16
-rw-r--r--usr.sbin/ntpd/ntp_dns.c9
-rw-r--r--usr.sbin/ntpd/ntpd.c54
3 files changed, 19 insertions, 60 deletions
diff --git a/usr.sbin/ntpd/ntp.c b/usr.sbin/ntpd/ntp.c
index 9c03747e33f..d3cb8ca461d 100644
--- a/usr.sbin/ntpd/ntp.c
+++ b/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 <henning@openbsd.org>
@@ -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/usr.sbin/ntpd/ntp_dns.c b/usr.sbin/ntpd/ntp_dns.c
index a8dcf98c60b..b9611c48eec 100644
--- a/usr.sbin/ntpd/ntp_dns.c
+++ b/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 <henning@openbsd.org>
@@ -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/usr.sbin/ntpd/ntpd.c b/usr.sbin/ntpd/ntpd.c
index 2df47e84852..3be7306bcfa 100644
--- a/usr.sbin/ntpd/ntpd.c
+++ b/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 <henning@openbsd.org>
@@ -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);