From: Roy Marples Date: Tue, 16 Jun 2020 11:58:16 +0000 (+0000) Subject: privsep: Don't handle any signals meant for the main process X-Git-Tag: v9.1.3~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84a8cab4e03c42b445fbcb33c3c03dd93e8803cc;p=thirdparty%2Fdhcpcd.git privsep: Don't handle any signals meant for the main process Just incase someone issues a killall -HUP dhcpcd --- diff --git a/src/dhcpcd.c b/src/dhcpcd.c index e030ff38..18e373c9 100644 --- a/src/dhcpcd.c +++ b/src/dhcpcd.c @@ -1409,6 +1409,9 @@ dhcpcd_signal_cb(int sig, void *arg) } if (sig != SIGCHLD && ctx->options & DHCPCD_FORKED) { + if (sig == SIGHUP) + return; + pid_t pid = pidfile_read(ctx->pidfile); if (pid == -1) { if (errno != ENOENT) diff --git a/src/privsep-bpf.c b/src/privsep-bpf.c index 6189349d..69a38b4c 100644 --- a/src/privsep-bpf.c +++ b/src/privsep-bpf.c @@ -175,6 +175,16 @@ ps_bpf_signal_bpfcb(int sig, void *arg) { struct dhcpcd_ctx *ctx = arg; + /* Ignore dhcpcd signals */ + switch (sig) { + case SIGINT: + case SIGALRM: + case SIGHUP: + case SIGUSR1: + case SIGUSR2: + return; + } + eloop_exit(ctx->eloop, sig == SIGTERM ? EXIT_SUCCESS : EXIT_FAILURE); } diff --git a/src/privsep-control.c b/src/privsep-control.c index 619171f8..9f9b554c 100644 --- a/src/privsep-control.c +++ b/src/privsep-control.c @@ -100,9 +100,15 @@ ps_ctl_signalcb(int sig, void *arg) { struct dhcpcd_ctx *ctx = arg; - /* Ignore SIGINT, respect PS_STOP command or SIGTERM. */ - if (sig == SIGINT) + /* Ignore dhcpcd signals */ + switch (sig) { + case SIGINT: + case SIGALRM: + case SIGHUP: + case SIGUSR1: + case SIGUSR2: return; + } shutdown(ctx->ps_control_fd, SHUT_RDWR); eloop_exit(ctx->eloop, sig == SIGTERM ? EXIT_SUCCESS : EXIT_FAILURE); diff --git a/src/privsep-inet.c b/src/privsep-inet.c index 0ac2b39a..44013a28 100644 --- a/src/privsep-inet.c +++ b/src/privsep-inet.c @@ -296,9 +296,15 @@ ps_inet_signalcb(int sig, void *arg) { struct dhcpcd_ctx *ctx = arg; - /* Ignore SIGINT, respect PS_STOP command or SIGTERM. */ - if (sig == SIGINT) + /* Ignore dhcpcd signals */ + switch (sig) { + case SIGINT: + case SIGALRM: + case SIGHUP: + case SIGUSR1: + case SIGUSR2: return; + } shutdown(ctx->ps_inet_fd, SHUT_RDWR); eloop_exit(ctx->eloop, sig == SIGTERM ? EXIT_SUCCESS : EXIT_FAILURE); diff --git a/src/privsep-root.c b/src/privsep-root.c index 46daeb07..98829aea 100644 --- a/src/privsep-root.c +++ b/src/privsep-root.c @@ -686,23 +686,24 @@ ps_root_signalcb(int sig, void *arg) { struct dhcpcd_ctx *ctx = arg; - /* Ignore SIGINT, respect PS_STOP command or SIGTERM. */ - if (sig == SIGINT) + /* Ignore dhcpcd signals, but reap children */ + switch (sig) { + case SIGINT: + case SIGALRM: + case SIGHUP: + case SIGUSR1: + case SIGUSR2: return; - - /* Reap children */ - if (sig == SIGCHLD) { + case SIGCHLD: while (waitpid(-1, NULL, WNOHANG) > 0) ; return; } - logerrx("process %d unexpectedly terminating on signal %d", - getpid(), sig); - if (ctx->ps_root_pid == getpid()) { - shutdown(ctx->ps_root_fd, SHUT_RDWR); - shutdown(ctx->ps_data_fd, SHUT_RDWR); - } + logerrx("%s: process %d unexpectedly terminating on signal %d", + __func__, getpid(), sig); + shutdown(ctx->ps_root_fd, SHUT_RDWR); + shutdown(ctx->ps_data_fd, SHUT_RDWR); eloop_exit(ctx->eloop, sig == SIGTERM ? EXIT_SUCCESS : EXIT_FAILURE); }