diff options
author | Rafael Zalamena <rzalamena@cvs.openbsd.org> | 2016-08-30 13:46:38 +0000 |
---|---|---|
committer | Rafael Zalamena <rzalamena@cvs.openbsd.org> | 2016-08-30 13:46:38 +0000 |
commit | af3989ff29d0fba3c2837c234fe6f9fc7d4d9dba (patch) | |
tree | ec5493ece1e81d675d5b00042b6b07a2c95ce21d /usr.sbin/httpd/httpd.c | |
parent | 16dcdac91f3bafc2612840322893135f6eeec01c (diff) |
Terminate daemon using the socket status instead of watching SIGCHLD or
kill()ing child process.
"Looks good to me" millert@
ok benno@
Diffstat (limited to 'usr.sbin/httpd/httpd.c')
-rw-r--r-- | usr.sbin/httpd/httpd.c | 54 |
1 files changed, 3 insertions, 51 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); |