]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
privsep: Simplyfy signal handling
authorRoy Marples <roy@marples.name>
Tue, 16 Jun 2020 19:58:17 +0000 (20:58 +0100)
committerRoy Marples <roy@marples.name>
Tue, 16 Jun 2020 19:58:17 +0000 (20:58 +0100)
All privsep processes only need to act on SIGTERM.
The privileged actioneer also needs to act on SIGCHLD.

src/privsep-bpf.c
src/privsep-control.c
src/privsep-inet.c
src/privsep-root.c

index 69a38b4cde5b596132a9058ebafd54a774e38e67..6892bf2a6a822feace4e3831e750af99e93f46b1 100644 (file)
@@ -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
index 9f9b554c68e3d4cf230e9ef745b93445681881e3..306ab58fa16998b13256bf3a3818c76d0b994881 100644 (file)
@@ -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
index 44013a28e0bc9e1dbabaa4b4eff2770e8af65ed8..8bc0c2eaf0a0f0d51a41eac94309c77ad3fce998 100644 (file)
@@ -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
index 9129cc509cb5285f8e44fea6cc0a1fd8df501538..f1b4074531b4593eb7f39dc77af58e8d18f0f119 100644 (file)
@@ -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 *);