]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
privsep: Try sending error if we cannot send the message.
authorRoy Marples <roy@marples.name>
Fri, 6 Jan 2023 11:14:45 +0000 (11:14 +0000)
committerRoy Marples <roy@marples.name>
Fri, 6 Jan 2023 11:21:05 +0000 (11:21 +0000)
There is an error sending a reply from an INET6 sysctl RT dump
on FreeBSD-14 using the dhcpcd-9 branch.
It seems to be related to capsicum and doesn't happen on FreeBSD-13.
We should handle the error gracefully and allow dhcpcd to try to
contuinue regardless.

src/privsep-root.c

index 0bf2345c60769583b3116af931e2746d29d9fb9d..5fda1626cceab35e063effd34b6515beca48e613 100644 (file)
@@ -209,12 +209,26 @@ ps_root_writeerror(struct dhcpcd_ctx *ctx, ssize_t result,
                { .iov_base = &psr, .iov_len = sizeof(psr) },
                { .iov_base = data, .iov_len = len },
        };
+       ssize_t err;
 
 #ifdef PRIVSEP_DEBUG
        logdebugx("%s: result %zd errno %d", __func__, result, errno);
 #endif
 
-       return writev(ctx->ps_root->psp_fd, iov, __arraycount(iov));
+       err = writev(ctx->ps_root->psp_fd, iov, __arraycount(iov));
+
+       /* Error sending the message? Try sending the error of sending. */
+       if (err == -1) {
+               logerr("%s: result=%zd, data=%p, len=%zu",
+                   __func__, result, data, len);
+               psr.psr_result = err;
+               psr.psr_errno = errno;
+               iov[1].iov_base = NULL;
+               iov[1].iov_len = 0;
+               err = writev(ctx->ps_root->psp_fd, iov, __arraycount(iov));
+       }
+
+       return err;
 }
 
 static ssize_t