Mercurial > hg > dhcpcd
changeset 5371:0c4a9b4da8e6 draft
privsep: Simplyfy signal handling
All privsep processes only need to act on SIGTERM.
The privileged actioneer also needs to act on SIGCHLD.
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Tue, 16 Jun 2020 20:58:17 +0100 |
| parents | ca830b3b9a58 |
| children | a64688cee252 |
| files | src/privsep-bpf.c src/privsep-control.c src/privsep-inet.c src/privsep-root.c |
| diffstat | 4 files changed, 11 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/src/privsep-bpf.c Tue Jun 16 17:31:47 2020 +0100 +++ b/src/privsep-bpf.c Tue Jun 16 20:58:17 2020 +0100 @@ -175,17 +175,10 @@ { 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
--- a/src/privsep-control.c Tue Jun 16 17:31:47 2020 +0100 +++ b/src/privsep-control.c Tue Jun 16 20:58:17 2020 +0100 @@ -100,18 +100,11 @@ { 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
--- a/src/privsep-inet.c Tue Jun 16 17:31:47 2020 +0100 +++ b/src/privsep-inet.c Tue Jun 16 20:58:17 2020 +0100 @@ -296,18 +296,11 @@ { 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
--- a/src/privsep-root.c Tue Jun 16 17:31:47 2020 +0100 +++ b/src/privsep-root.c Tue Jun 16 20:58:17 2020 +0100 @@ -678,25 +678,18 @@ { 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 *);
