|
@ -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> |
|
|
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> |
|
@ -41,7 +41,7 @@ |
|
|
void sighdlr(int); |
|
|
void sighdlr(int); |
|
|
__dead void usage(void); |
|
|
__dead void usage(void); |
|
|
int main(int, char *[]); |
|
|
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(struct ntpd_conf *, const char *, uid_t, gid_t); |
|
|
int dispatch_imsg_ctl(struct ntpd_conf *); |
|
|
int dispatch_imsg_ctl(struct ntpd_conf *); |
|
|
void reset_adjtime(void); |
|
|
void reset_adjtime(void); |
|
@ -110,7 +110,7 @@ main(int argc, char *argv[]) |
|
|
{ |
|
|
{ |
|
|
struct ntpd_conf lconf; |
|
|
struct ntpd_conf lconf; |
|
|
struct pollfd *pfd = NULL; |
|
|
struct pollfd *pfd = NULL; |
|
|
pid_t chld_pid = 0, pid; |
|
|
|
|
|
|
|
|
pid_t pid; |
|
|
const char *conffile; |
|
|
const char *conffile; |
|
|
int ch, nfds, i, j; |
|
|
int ch, nfds, i, j; |
|
|
int pipe_chld[2]; |
|
|
int pipe_chld[2]; |
|
@ -227,7 +227,7 @@ main(int argc, char *argv[]) |
|
|
signal(SIGCHLD, sighdlr); |
|
|
signal(SIGCHLD, sighdlr); |
|
|
|
|
|
|
|
|
/* fork child process */ |
|
|
/* 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]"); |
|
|
log_procinit("[priv]"); |
|
|
readfreq(); |
|
|
readfreq(); |
|
@ -315,19 +315,15 @@ main(int argc, char *argv[]) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (sigchld) { |
|
|
if (sigchld) { |
|
|
if (check_child(chld_pid, "child")) { |
|
|
|
|
|
quit = 1; |
|
|
|
|
|
chld_pid = 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
check_child(); |
|
|
sigchld = 0; |
|
|
sigchld = 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
signal(SIGCHLD, SIG_DFL); |
|
|
signal(SIGCHLD, SIG_DFL); |
|
|
|
|
|
|
|
|
if (chld_pid) |
|
|
|
|
|
kill(chld_pid, SIGTERM); |
|
|
|
|
|
|
|
|
/* Close socket and start shutdown. */ |
|
|
|
|
|
close(ibuf->fd); |
|
|
|
|
|
|
|
|
do { |
|
|
do { |
|
|
if ((pid = wait(NULL)) == -1 && |
|
|
if ((pid = wait(NULL)) == -1 && |
|
@ -341,36 +337,19 @@ main(int argc, char *argv[]) |
|
|
return (0); |
|
|
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; |
|
|
pid_t pid; |
|
|
|
|
|
|
|
|
do { |
|
|
do { |
|
|
pid = waitpid(WAIT_ANY, &status, WNOHANG); |
|
|
pid = waitpid(WAIT_ANY, &status, WNOHANG); |
|
|
if (pid <= 0) { |
|
|
|
|
|
|
|
|
if (pid <= 0) |
|
|
continue; |
|
|
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 |
|
|
int |
|
@ -381,14 +360,9 @@ dispatch_imsg(struct ntpd_conf *lconf, const char *pw_dir, |
|
|
int n; |
|
|
int n; |
|
|
double d; |
|
|
double d; |
|
|
|
|
|
|
|
|
if ((n = imsg_read(ibuf)) == -1 && errno != EAGAIN) |
|
|
|
|
|
|
|
|
if (((n = imsg_read(ibuf)) == -1 && errno != EAGAIN) || n == 0) |
|
|
return (-1); |
|
|
return (-1); |
|
|
|
|
|
|
|
|
if (n == 0) { /* connection closed */ |
|
|
|
|
|
log_warnx("dispatch_imsg in main: pipe closed"); |
|
|
|
|
|
return (-1); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (;;) { |
|
|
for (;;) { |
|
|
if ((n = imsg_get(ibuf, &imsg)) == -1) |
|
|
if ((n = imsg_get(ibuf, &imsg)) == -1) |
|
|
return (-1); |
|
|
return (-1); |
|
|