Mercurial > hg > dhcpcd
changeset 5365:57b9f2292dfb draft
privsep: Don't handle any signals meant for the main process
Just incase someone issues a killall -HUP dhcpcd
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Tue, 16 Jun 2020 11:58:16 +0000 |
| parents | fe45c5b59de1 |
| children | 1d7408a4160b |
| files | src/dhcpcd.c src/privsep-bpf.c src/privsep-control.c src/privsep-inet.c src/privsep-root.c |
| diffstat | 5 files changed, 41 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/dhcpcd.c Tue Jun 16 10:26:25 2020 +0000 +++ b/src/dhcpcd.c Tue Jun 16 11:58:16 2020 +0000 @@ -1409,6 +1409,9 @@ } if (sig != SIGCHLD && ctx->options & DHCPCD_FORKED) { + if (sig == SIGHUP) + return; + pid_t pid = pidfile_read(ctx->pidfile); if (pid == -1) { if (errno != ENOENT)
--- a/src/privsep-bpf.c Tue Jun 16 10:26:25 2020 +0000 +++ b/src/privsep-bpf.c Tue Jun 16 11:58:16 2020 +0000 @@ -175,6 +175,16 @@ { 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); }
--- a/src/privsep-control.c Tue Jun 16 10:26:25 2020 +0000 +++ b/src/privsep-control.c Tue Jun 16 11:58:16 2020 +0000 @@ -100,9 +100,15 @@ { 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);
--- a/src/privsep-inet.c Tue Jun 16 10:26:25 2020 +0000 +++ b/src/privsep-inet.c Tue Jun 16 11:58:16 2020 +0000 @@ -296,9 +296,15 @@ { 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);
--- a/src/privsep-root.c Tue Jun 16 10:26:25 2020 +0000 +++ b/src/privsep-root.c Tue Jun 16 11:58:16 2020 +0000 @@ -686,23 +686,24 @@ { 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); }
