]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
privsep: Fix a shutdown race
authorRoy Marples <roy@marples.name>
Wed, 10 Jun 2020 15:32:04 +0000 (16:32 +0100)
committerRoy Marples <roy@marples.name>
Wed, 10 Jun 2020 15:32:04 +0000 (16:32 +0100)
Only test a successful stop IPC command.
By the time we shutdown the socket to be extra nice, the
process we sent stop to could have already exited, therefore
we can discard any error.

src/privsep-root.c
src/privsep.c

index efafc20a599158eb8305ae415da414d6030eb1aa..46daeb0766ee6f9a401f1aaf8d9f2bc874cb0c6a 100644 (file)
@@ -480,7 +480,6 @@ ps_root_recvmsgcb(void *arg, struct ps_msghdr *psm, struct msghdr *msg)
                        shutdown(psp->psp_fd, SHUT_RDWR);
                        close(psp->psp_fd);
                        psp->psp_fd = -1;
-                       ps_dostop(ctx, &psp->psp_pid, &psp->psp_fd);
                        ps_freeprocess(psp);
                }
                return 0;
index b2f3b3096c55e368feaba1d3e4e9d255576425dd..d05681aabe5a827915f3557ccaef3bb5f0a6584a 100644 (file)
@@ -401,17 +401,16 @@ ps_dostop(struct dhcpcd_ctx *ctx, pid_t *pid, int *fd)
        int err = 0;
 
 #ifdef PRIVSEP_DEBUG
-       logdebugx("%s: pid %d fd %d", __func__, *pid, *fd);
+       logdebugx("%s: pid=%d fd=%d", __func__, *pid, *fd);
 #endif
 
        if (*fd != -1) {
                eloop_event_delete(ctx->eloop, *fd);
-               if (ps_sendcmd(ctx, *fd, PS_STOP, 0, NULL, 0) == -1 ||
-                   shutdown(*fd, SHUT_RDWR) == -1)
-               {
+               if (ps_sendcmd(ctx, *fd, PS_STOP, 0, NULL, 0) == -1) {
                        logerr(__func__);
                        err = -1;
                }
+               (void)shutdown(*fd, SHUT_RDWR);
                close(*fd);
                *fd = -1;
        }