From: W. Trevor King Date: Thu, 25 Oct 2012 11:46:34 +0000 (-0400) Subject: gpgme-tool: cleanup defunct children with waitpid(). X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=refs%2Fheads%2Fsocket;p=gpgme.git gpgme-tool: cleanup defunct children with waitpid(). Signed-off-by: W. Trevor King --- diff --git a/configure.ac b/configure.ac index bf5c15a..9e7cc4d 100644 --- a/configure.ac +++ b/configure.ac @@ -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. diff --git a/src/gpgme-tool.c b/src/gpgme-tool.c index ec22a91..25f0e44 100644 --- a/src/gpgme-tool.c +++ b/src/gpgme-tool.c @@ -41,6 +41,9 @@ #ifdef HAVE_UNISTD_H # include #endif +#ifdef HAVE_WAIT_H +# include +#endif #ifdef HAVE_LOCALE_H #include #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