diff options
| author | Roy Marples <roy@marples.name> | 2020-06-16 20:58:17 +0100 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2020-06-16 20:58:17 +0100 |
| commit | 9b3c9117fa48351e6b7e15176ace67163eccaecc (patch) | |
| tree | 54594ae90d09bf32937786f68ea2c40c6fdaaae7 | |
| parent | 7fbcfeda938e4f566b791c45dcc942e922abe63e (diff) | |
| download | dhcpcd-9b3c9117fa48351e6b7e15176ace67163eccaecc.tar.xz | |
privsep: Simplyfy signal handling
All privsep processes only need to act on SIGTERM.
The privileged actioneer also needs to act on SIGCHLD.
| -rw-r--r-- | src/privsep-bpf.c | 11 | ||||
| -rw-r--r-- | src/privsep-control.c | 11 | ||||
| -rw-r--r-- | src/privsep-inet.c | 11 | ||||
| -rw-r--r-- | src/privsep-root.c | 17 |
4 files changed, 11 insertions, 39 deletions
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 *); |
