chiark / gitweb /
Cope with programs which set SIGCHLD to SIG_IGN. (We assume they don't manipulate...
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 22 Jan 2017 11:52:07 +0000 (11:52 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 22 Jan 2017 11:52:07 +0000 (11:52 +0000)
debian/changelog
libauthbind.c

index f3e2c6baca6a0c2b5a854d5ed9e40db8374d2250..13566063eb74de2b523935361df48bc7e64e3f91 100644 (file)
@@ -1,5 +1,8 @@
-authbind (2.1.2~~iwj) unstable; urgency=low
+authbind (2.1.2) unstable; urgency=low
 
+  * Cope with programs which set SIGCHLD to SIG_IGN.  (We assume
+    they don't manipulate SIGCHLD on other threads, which is probably
+    true.)  Patch from Marco d'Itri, slightly modified.  Closes:#765587.
   * Fix one-letter typo in previous changelog entry.
 
  --
index a685ce3fe200c957a5f686a90eaf3e19811fb66b..42630e41a00686b66e3a41a6596deea8a16a1087 100644 (file)
@@ -146,9 +146,10 @@ int bind(int fd, const struct sockaddr *addr, socklen_t addrlen) {
   pid_t child, rchild;
   char portarg[5], addrarg[33];
   const char *afarg;
-  int i, r, status;
+  int i, r, status, restore_sigchild;
   const int *evilsignal;
   sigset_t block, saved;
+  struct sigaction old_sigchild;
   unsigned int portval;
 
   switch (addr->sa_family) {
@@ -195,6 +196,18 @@ int bind(int fd, const struct sockaddr *addr, socklen_t addrlen) {
   sprintf(portarg,"%04x",
          portval&0x0ffff);
 
+  restore_sigchild= 0;
+  if (sigaction(SIGCHLD,NULL,&old_sigchild)) return -1;
+  if (old_sigchild.sa_handler == SIG_IGN) {
+    struct sigaction new_sigchild;
+
+    new_sigchild.sa_handler= SIG_DFL;
+    sigemptyset(&new_sigchild.sa_mask);
+    new_sigchild.sa_flags= 0;
+    if (sigaction(SIGCHLD,&new_sigchild,&old_sigchild)) return -1;
+    restore_sigchild= 1;
+  }
+
   child= fork(); if (child==-1) goto x_err;
 
   if (!child) {
@@ -228,5 +241,13 @@ x_err:
   r= -1;
 x:
   if (sigprocmask(SIG_SETMASK,&saved,0)) abort();
+  if (restore_sigchild) {
+    if (sigaction(SIGCHLD,&old_sigchild,NULL)) return -1;
+    if (old_sigchild.sa_handler == SIG_IGN) {
+      int discard;
+      while (waitpid(-1, &discard, WNOHANG) > 0)
+       ;
+    }
+  }
   return r;
 }