gpgme-tool: cleanup defunct children with waitpid(). socket
authorW. Trevor King <wking@tremily.us>
Thu, 25 Oct 2012 11:46:34 +0000 (07:46 -0400)
committerW. Trevor King <wking@tremily.us>
Thu, 25 Oct 2012 11:46:34 +0000 (07:46 -0400)
Signed-off-by: W. Trevor King <wking@tremily.us>
configure.ac
src/gpgme-tool.c

index bf5c15aa67eee8ee2d7a2a9a8f86b08403b615cd..9e7cc4d9eca98b5d0a4ce9ea7424c1aa0ad8b483 100644 (file)
@@ -219,7 +219,7 @@ AM_CONDITIONAL(HAVE_PTHREAD, test "$have_pthread" = "yes")
 
 # Checks for header files.
 AC_CHECK_HEADERS_ONCE([locale.h signal.h sys/select.h sys/uio.h argp.h
-                       unistd.h sys/time.h sys/types.h sys/stat.h])
+                       unistd.h wait.h sys/time.h sys/types.h sys/stat.h])
 
 
 # Type checks.
index ec22a91e24c9293cf42990fcfa43fbf1b0d44c21..25f0e446f7d1010bd569dfe1977eb3d275a9d758 100644 (file)
@@ -41,6 +41,9 @@
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
 #endif
+#ifdef HAVE_WAIT_H
+# include <wait.h>
+#endif
 #ifdef HAVE_LOCALE_H
 #include <locale.h>
 #endif
@@ -3487,6 +3490,7 @@ gpgme_server (gpgme_tool_t gt, int socket_server)
 {
   gpg_error_t err;
   pid_t pid;
+  int status;
   assuan_fd_t sock = ASSUAN_INVALID_FD;
   assuan_fd_t filedes[2];
   struct server server;
@@ -3570,6 +3574,16 @@ gpgme_server (gpgme_tool_t gt, int socket_server)
               break;  /* child; continue setting up server */
             }
           /* parent; continue listening for other connections */
+#ifdef HAVE_WAIT_H
+          /* reap any defunct children */
+          do {
+            pid = waitpid(-1, &status, WNOHANG);
+            if (pid < 0) {
+              err = gpg_error_from_syserror ();
+              log_error (0, err, "waitpid() failed");
+            }
+          } while (pid);
+#endif
         }
 
 #ifdef HAVE_SIGNAL_H