work around missing SOCK_NONBLOCK/CLOEXEC on macos

This commit is contained in:
Omar Polo 2023-06-13 10:59:46 +00:00
parent 94893746ae
commit 1b9031f1fc
1 changed files with 14 additions and 2 deletions

16
proc.c
View File

@ -238,10 +238,16 @@ proc_init(struct privsep *ps, struct privsep_proc *procs, unsigned int nproc,
pa = &ps->ps_pipes[PROC_PARENT][0];
pb = &ps->ps_pipes[dst][proc];
if (socketpair(AF_UNIX,
SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC,
SOCK_STREAM,
PF_UNSPEC, fds) == -1)
fatal("%s: socketpair", __func__);
mark_nonblock(fds[0]);
mark_nonblock(fds[1]);
if (fcntl(fds[0], F_SETFD, FD_CLOEXEC) == -1 ||
fcntl(fds[1], F_SETFD, FD_CLOEXEC) == -1)
fatal("%s: fcntl F_SETFD", __func__);
pa->pp_pipes[dst][proc] = fds[0];
pb->pp_pipes[PROC_PARENT][0] = fds[1];
}
@ -432,10 +438,16 @@ proc_open(struct privsep *ps, int src, int dst)
pa = &ps->ps_pipes[src][i];
pb = &ps->ps_pipes[dst][j];
if (socketpair(AF_UNIX,
SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC,
SOCK_STREAM,
PF_UNSPEC, fds) == -1)
fatal("%s: socketpair", __func__);
mark_nonblock(fds[0]);
mark_nonblock(fds[1]);
if (fcntl(fds[0], F_SETFD, FD_CLOEXEC) == -1 ||
fcntl(fds[1], F_SETFD, FD_CLOEXEC) == -1)
fatal("%s: fcntl F_SETFD", __func__);
pa->pp_pipes[dst][j] = fds[0];
pb->pp_pipes[src][i] = fds[1];