X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/tripe/blobdiff_plain/388e0319a0faf48193658c82228133bd1ea24eb6..e9fac70c8cff251871c8177e7578f8ed055b7fc7:/server/privsep.c diff --git a/server/privsep.c b/server/privsep.c index 5bc2b892..d7063b63 100644 --- a/server/privsep.c +++ b/server/privsep.c @@ -32,6 +32,7 @@ /*----- Static variables --------------------------------------------------*/ static pid_t kid = -1; +static sig sig_chld; /*----- Fetching a tunnel file descriptor ---------------------------------*/ @@ -128,7 +129,7 @@ lose: * Use: Notices and reports child process death. */ -static void reap(int sig) +static void reap(int sig, void *p) { pid_t k; int st; @@ -173,6 +174,7 @@ void ps_split(int detachp) { pid_t kid; int fd[2]; + mdup_fd md[1]; const char *helper; if (socketpair(PF_UNIX, SOCK_STREAM, 0, fd)) { @@ -184,13 +186,14 @@ void ps_split(int detachp) if (!helper) helper = PRIVSEP_HELPER; fdflags(fd[0], 0, 0, FD_CLOEXEC, FD_CLOEXEC); fdflags(fd[1], 0, 0, FD_CLOEXEC, FD_CLOEXEC); - signal(SIGCHLD, reap); + sig_add(&sig_chld, SIGCHLD, reap, 0); kid = fork(); if (kid == 0) { signal(SIGCHLD, SIG_DFL); if (detachp) detachtty(); - if (dup2(fd[0], 0) < 0) goto lose; - close(fd[0]); close(fd[1]); + close(fd[1]); + md[0].cur = fd[0]; md[0].want = STDIN_FILENO; + if (mdup(md, 1)) goto lose; execl(helper, helper, (char *)0); lose: fprintf(stderr, "helper: failed to run helper: %s\n", strerror(errno));