Index: b/dirmngr/ldap-wrapper.c =================================================================== --- b/dirmngr/ldap-wrapper.c +++ b/dirmngr/ldap-wrapper.c @@ -140,16 +140,39 @@ return 0; } +/* Cleanup a process with the given pid. If the pid is -1 it is ignored + otherwise the process will be killed released and waited on. */ +static void +destroy_process (pid_t pid) +{ + gpg_error_t err; + int status; + + if (pid == (pid_t)(-1)) + return; + + gnupg_kill_process (pid); + gnupg_release_process (pid); + err = gnupg_wait_process ("[dirmngr_ldap]", pid, 0, &status); + + if (!err) + return; + + if (gpg_err_code (err) == GPG_ERR_TIMEOUT) + log_debug ("ldap wrapper %d still running.", pid); + else if (gpg_err_code (err) == GPG_ERR_GENERAL) + log_debug ("ldap wrapper %d exited with error: %d", pid, status); + else + log_debug ("ldap wrapper %d wait returned error: %s", pid, + gpg_strerror (err)); + +} /* Release the wrapper context and kill a running wrapper process. */ static void destroy_wrapper (struct wrapper_context_s *ctx) { - if (ctx->pid != (pid_t)(-1)) - { - gnupg_kill_process (ctx->pid); - gnupg_release_process (ctx->pid); - } + destroy_process (ctx->pid); ksba_reader_release (ctx->reader); SAFE_CLOSE (ctx->fd); SAFE_CLOSE (ctx->log_fd); @@ -378,7 +401,7 @@ if (ctx->pid != (pid_t)(-1) && ctx->stamp != (time_t)(-1) && ctx->stamp < exptime) { - gnupg_kill_process (ctx->pid); + destroy_process (ctx->pid); ctx->stamp = (time_t)(-1); log_info (_("ldap wrapper %d stalled - killing\n"), (int)ctx->pid); @@ -502,6 +525,7 @@ if (ctx->fd_error) log_info (_("reading from ldap wrapper %d failed: %s\n"), ctx->printable_pid, gpg_strerror (ctx->fd_error)); + destroy_process (ctx->pid); break; } } @@ -516,10 +540,9 @@ for (ctx=wrapper_list; ctx; ctx=ctx->next) if (ctx->ctrl && ctx->ctrl == ctrl) { + destroy_process (ctx->pid); ctx->ctrl->refcount--; ctx->ctrl = NULL; - if (ctx->pid != (pid_t)(-1)) - gnupg_kill_process (ctx->pid); if (ctx->fd_error) log_info (_("reading from ldap wrapper %d failed: %s\n"), ctx->printable_pid, gpg_strerror (ctx->fd_error)); @@ -749,6 +772,7 @@ log_error (_("error initializing reader object: %s\n"), gpg_strerror (err)); destroy_wrapper (ctx); + destroy_process (ctx->pid); ksba_reader_release (*reader); *reader = NULL; return err;