chiark / gitweb /
server/tests.at, t/keyring-*: Handle three-party tests.
[tripe] / server / privsep.c
index 5bc2b89220d3d4b4d7c2085ccd39d43ec605201c..d7063b63809eeb253c51db262757c7f5262dfc50 100644 (file)
@@ -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));