-/* $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>
#include <sys/queue.h>
#include <sys/socket.h>
#include <sys/stat.h>
-#include <sys/wait.h>
#include <sys/resource.h>
#include <netinet/in.h>
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__);
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");
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);
-/* $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>
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