diff options
-rw-r--r-- | usr.sbin/httpd/httpd.c | 54 | ||||
-rw-r--r-- | usr.sbin/httpd/proc.c | 34 |
2 files changed, 27 insertions, 61 deletions
diff --git a/usr.sbin/httpd/httpd.c b/usr.sbin/httpd/httpd.c index f5682a863d8..4c73252e5f7 100644 --- a/usr.sbin/httpd/httpd.c +++ b/usr.sbin/httpd/httpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: httpd.c,v 1.58 2016/08/26 12:24:21 rzalamena Exp $ */ +/* $OpenBSD: httpd.c,v 1.59 2016/08/30 13:46:37 rzalamena Exp $ */ /* * Copyright (c) 2014 Reyk Floeter <reyk@openbsd.org> @@ -20,7 +20,6 @@ #include <sys/queue.h> #include <sys/socket.h> #include <sys/stat.h> -#include <sys/wait.h> #include <sys/resource.h> #include <netinet/in.h> @@ -70,56 +69,11 @@ void parent_sig_handler(int sig, short event, void *arg) { struct privsep *ps = arg; - int die = 0, status, fail, id; - pid_t pid; - char *cause; switch (sig) { case SIGTERM: case SIGINT: - die = 1; - /* FALLTHROUGH */ - case SIGCHLD: - do { - int len; - - pid = waitpid(WAIT_ANY, &status, WNOHANG); - if (pid <= 0) - continue; - - fail = 0; - if (WIFSIGNALED(status)) { - fail = 1; - len = asprintf(&cause, "terminated; signal %d", - WTERMSIG(status)); - } else if (WIFEXITED(status)) { - if (WEXITSTATUS(status) != 0) { - fail = 1; - len = asprintf(&cause, - "exited abnormally"); - } else - len = asprintf(&cause, "exited okay"); - } else - fatalx("unexpected cause of SIGCHLD"); - - if (len == -1) - fatal("asprintf"); - - die = 1; - - for (id = 0; id < PROC_MAX; id++) - if (pid == ps->ps_pid[id]) { - if (fail) - log_warnx("lost child: %s %s", - ps->ps_title[id], cause); - break; - } - - free(cause); - } while (pid > 0 || (pid == -1 && errno == EINTR)); - - if (die) - parent_shutdown(ps->ps_env); + parent_shutdown(ps->ps_env); break; case SIGHUP: log_info("%s: reload requested with SIGHUP", __func__); @@ -247,7 +201,7 @@ main(int argc, char *argv[]) proc_init(ps, procs, nitems(procs)); log_procinit("parent"); - if (pledge("stdio rpath wpath cpath inet dns proc ioctl sendfd", + if (pledge("stdio rpath wpath cpath inet dns ioctl sendfd", NULL) == -1) fatal("pledge"); @@ -255,14 +209,12 @@ main(int argc, char *argv[]) signal_set(&ps->ps_evsigint, SIGINT, parent_sig_handler, ps); signal_set(&ps->ps_evsigterm, SIGTERM, parent_sig_handler, ps); - signal_set(&ps->ps_evsigchld, SIGCHLD, parent_sig_handler, ps); signal_set(&ps->ps_evsighup, SIGHUP, parent_sig_handler, ps); signal_set(&ps->ps_evsigpipe, SIGPIPE, parent_sig_handler, ps); signal_set(&ps->ps_evsigusr1, SIGUSR1, parent_sig_handler, ps); signal_add(&ps->ps_evsigint, NULL); signal_add(&ps->ps_evsigterm, NULL); - signal_add(&ps->ps_evsigchld, NULL); signal_add(&ps->ps_evsighup, NULL); signal_add(&ps->ps_evsigpipe, NULL); signal_add(&ps->ps_evsigusr1, NULL); diff --git a/usr.sbin/httpd/proc.c b/usr.sbin/httpd/proc.c index 6f6b8db3560..a060250a001 100644 --- a/usr.sbin/httpd/proc.c +++ b/usr.sbin/httpd/proc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.c,v 1.17 2016/08/27 11:13:16 rzalamena Exp $ */ +/* $OpenBSD: proc.c,v 1.18 2016/08/30 13:46:37 rzalamena Exp $ */ /* * Copyright (c) 2010 - 2014 Reyk Floeter <reyk@openbsd.org> @@ -125,23 +125,37 @@ proc_init(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc) void proc_kill(struct privsep *ps) { + char *cause; pid_t pid; - unsigned int i; + int len, status; if (privsep_process != PROC_PARENT) return; - for (i = 0; i < PROC_MAX; i++) { - if (ps->ps_pid[i] == 0) - continue; - killpg(ps->ps_pid[i], SIGTERM); - } + proc_close(ps); do { - pid = waitpid(WAIT_ANY, NULL, 0); - } while (pid != -1 || (pid == -1 && errno == EINTR)); + pid = waitpid(WAIT_ANY, &status, 0); + if (pid <= 0) + continue; - proc_close(ps); + if (WIFSIGNALED(status)) { + len = asprintf(&cause, "terminated; signal %d", + WTERMSIG(status)); + } else if (WIFEXITED(status)) { + if (WEXITSTATUS(status) != 0) + len = asprintf(&cause, "exited abnormally"); + else + len = asprintf(&cause, "exited okay"); + } else + len = -1; + + if (len != -1) { + log_warnx("lost child: pid %u %s", pid, cause); + free(cause); + } else + log_warnx("lost child: pid %u", pid); + } while (pid != -1 || (pid == -1 && errno == EINTR)); } void |