Browse Source

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@
OPENBSD_6_1
rzalamena 8 years ago
parent
commit
4e462f2ebb
3 changed files with 19 additions and 60 deletions
  1. +3
    -13
      src/usr.sbin/ntpd/ntp.c
  2. +2
    -7
      src/usr.sbin/ntpd/ntp_dns.c
  3. +14
    -40
      src/usr.sbin/ntpd/ntpd.c

+ 3
- 13
src/usr.sbin/ntpd/ntp.c View File

@ -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);


+ 2
- 7
src/usr.sbin/ntpd/ntp_dns.c View File

@ -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);


+ 14
- 40
src/usr.sbin/ntpd/ntpd.c View File

@ -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);


Loading…
Cancel
Save