From: Roy Marples Date: Tue, 16 Jun 2020 19:58:17 +0000 (+0100) Subject: privsep: Simplyfy signal handling X-Git-Tag: v9.1.3~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9b3c9117fa48351e6b7e15176ace67163eccaecc;p=thirdparty%2Fdhcpcd.git privsep: Simplyfy signal handling All privsep processes only need to act on SIGTERM. The privileged actioneer also needs to act on SIGCHLD. --- diff --git a/src/privsep-bpf.c b/src/privsep-bpf.c index 69a38b4c..6892bf2a 100644 --- a/src/privsep-bpf.c +++ b/src/privsep-bpf.c @@ -175,17 +175,10 @@ 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: + if (sig != SIGTERM) return; - } - eloop_exit(ctx->eloop, sig == SIGTERM ? EXIT_SUCCESS : EXIT_FAILURE); + eloop_exit(ctx->eloop, EXIT_SUCCESS); } ssize_t diff --git a/src/privsep-control.c b/src/privsep-control.c index 9f9b554c..306ab58f 100644 --- a/src/privsep-control.c +++ b/src/privsep-control.c @@ -100,18 +100,11 @@ ps_ctl_signalcb(int sig, void *arg) { struct dhcpcd_ctx *ctx = arg; - /* Ignore dhcpcd signals */ - switch (sig) { - case SIGINT: - case SIGALRM: - case SIGHUP: - case SIGUSR1: - case SIGUSR2: + if (sig != SIGTERM) return; - } shutdown(ctx->ps_control_fd, SHUT_RDWR); - eloop_exit(ctx->eloop, sig == SIGTERM ? EXIT_SUCCESS : EXIT_FAILURE); + eloop_exit(ctx->eloop, EXIT_SUCCESS); } ssize_t diff --git a/src/privsep-inet.c b/src/privsep-inet.c index 44013a28..8bc0c2ea 100644 --- a/src/privsep-inet.c +++ b/src/privsep-inet.c @@ -296,18 +296,11 @@ ps_inet_signalcb(int sig, void *arg) { struct dhcpcd_ctx *ctx = arg; - /* Ignore dhcpcd signals */ - switch (sig) { - case SIGINT: - case SIGALRM: - case SIGHUP: - case SIGUSR1: - case SIGUSR2: + if (sig != SIGTERM) return; - } shutdown(ctx->ps_inet_fd, SHUT_RDWR); - eloop_exit(ctx->eloop, sig == SIGTERM ? EXIT_SUCCESS : EXIT_FAILURE); + eloop_exit(ctx->eloop, EXIT_SUCCESS); } ssize_t diff --git a/src/privsep-root.c b/src/privsep-root.c index 9129cc50..f1b40745 100644 --- a/src/privsep-root.c +++ b/src/privsep-root.c @@ -678,25 +678,18 @@ ps_root_signalcb(int sig, void *arg) { struct dhcpcd_ctx *ctx = arg; - /* Ignore dhcpcd signals, but reap children */ - switch (sig) { - case SIGINT: - case SIGALRM: - case SIGHUP: - case SIGUSR1: - case SIGUSR2: - return; - case SIGCHLD: + if (sig == SIGCHLD) { while (waitpid(-1, NULL, WNOHANG) > 0) ; return; } - logerrx("%s: process %d unexpectedly terminating on signal %d", - __func__, getpid(), sig); + if (sig != SIGTERM) + return; + shutdown(ctx->ps_root_fd, SHUT_RDWR); shutdown(ctx->ps_data_fd, SHUT_RDWR); - eloop_exit(ctx->eloop, sig == SIGTERM ? EXIT_SUCCESS : EXIT_FAILURE); + eloop_exit(ctx->eloop, EXIT_SUCCESS); } int (*handle_interface)(void *, int, const char *);