1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-24 10:39:57 +01:00

dirmngr: Cleanup zombies and fix hang on shutdown.

* dirmngr/ldap-wrapper.c (ldap_wrapper_thread): Move nfds computation
into the loop.  Check the queue also on timeout.  Close log_fd and
reader context on EOF or error.
--

The major bug here was that on an EOF of the log fd the log fd was not
closed and thus the final queue item removal could not work.  Checking
the queue on a timeout is not really necessary but it help in case
there is a race condition lingering.

GnuPG-bug-id: 1838, 1978
Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2015-06-16 18:08:32 +02:00
parent eb4d33cba9
commit 685b782a18
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B

View File

@ -259,13 +259,28 @@ ldap_wrapper_thread (void *dummy)
struct timespec abstime; struct timespec abstime;
struct timespec curtime; struct timespec curtime;
struct timespec timeout; struct timespec timeout;
int saved_errno; fd_set fdset;
fd_set fdset, read_fdset;
int ret; int ret;
time_t exptime; time_t exptime;
(void)dummy; (void)dummy;
npth_clock_gettime (&abstime);
abstime.tv_sec += TIMERTICK_INTERVAL;
for (;;)
{
int any_action = 0;
npth_clock_gettime (&curtime);
if (!(npth_timercmp (&curtime, &abstime, <)))
{
/* Inactivity is checked below. Nothing else to do. */
npth_clock_gettime (&abstime);
abstime.tv_sec += TIMERTICK_INTERVAL;
}
npth_timersub (&abstime, &curtime, &timeout);
FD_ZERO (&fdset); FD_ZERO (&fdset);
nfds = -1; nfds = -1;
for (ctx = wrapper_list; ctx; ctx = ctx->next) for (ctx = wrapper_list; ctx; ctx = ctx->next)
@ -279,45 +294,20 @@ ldap_wrapper_thread (void *dummy)
} }
nfds++; nfds++;
npth_clock_gettime (&abstime);
abstime.tv_sec += TIMERTICK_INTERVAL;
for (;;)
{
int any_action = 0;
/* POSIX says that fd_set should be implemented as a structure,
thus a simple assignment is fine to copy the entire set. */
read_fdset = fdset;
npth_clock_gettime (&curtime);
if (!(npth_timercmp (&curtime, &abstime, <)))
{
/* Inactivity is checked below. Nothing else to do. */
// handle_tick ();
npth_clock_gettime (&abstime);
abstime.tv_sec += TIMERTICK_INTERVAL;
}
npth_timersub (&abstime, &curtime, &timeout);
/* FIXME: For Windows, we have to use a reader thread on the /* FIXME: For Windows, we have to use a reader thread on the
pipe that signals an event (and a npth_select_ev variant). */ pipe that signals an event (and a npth_select_ev variant). */
ret = npth_pselect (nfds + 1, &read_fdset, NULL, NULL, &timeout, NULL); ret = npth_pselect (nfds + 1, &fdset, NULL, NULL, &timeout, NULL);
saved_errno = errno; if (ret == -1)
{
if (ret == -1 && saved_errno != EINTR) if (errno != EINTR)
{ {
log_error (_("npth_select failed: %s - waiting 1s\n"), log_error (_("npth_select failed: %s - waiting 1s\n"),
strerror (saved_errno)); strerror (errno));
npth_sleep (1); npth_sleep (1);
}
continue; continue;
} }
if (ret <= 0)
/* Interrupt or timeout. Will be handled when calculating the
next timeout. */
continue;
/* All timestamps before exptime should be considered expired. */ /* All timestamps before exptime should be considered expired. */
exptime = time (NULL); exptime = time (NULL);
if (exptime > INACTIVITY_TIMEOUT) if (exptime > INACTIVITY_TIMEOUT)
@ -331,11 +321,16 @@ ldap_wrapper_thread (void *dummy)
for (ctx = wrapper_list; ctx; ctx = ctx->next) for (ctx = wrapper_list; ctx; ctx = ctx->next)
{ {
/* Check whether there is any logging to be done. */ /* Check whether there is any logging to be done. */
if (nfds && ctx->log_fd != -1 && FD_ISSET (ctx->log_fd, &read_fdset)) if (nfds && ctx->log_fd != -1 && FD_ISSET (ctx->log_fd, &fdset))
{ {
if (read_log_data (ctx)) if (read_log_data (ctx))
{
ksba_reader_release (ctx->reader);
ctx->reader = NULL;
SAFE_CLOSE (ctx->log_fd);
any_action = 1; any_action = 1;
} }
}
/* Check whether the process is still running. */ /* Check whether the process is still running. */
if (ctx->pid != (pid_t)(-1)) if (ctx->pid != (pid_t)(-1))