From: Timo Sirainen Date: Tue, 8 Sep 2009 18:49:35 +0000 (-0400) Subject: lib-signals: Don't assert-crash with nested signal handler calls. X-Git-Tag: 2.0.alpha1~147 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=278410eafcd8db5f2b352e0ac3bc8ef322137e9d;p=thirdparty%2Fdovecot%2Fcore.git lib-signals: Don't assert-crash with nested signal handler calls. --HG-- branch : HEAD --- diff --git a/src/lib/lib-signals.c b/src/lib/lib-signals.c index fe13c170b3..db5c6110c8 100644 --- a/src/lib/lib-signals.c +++ b/src/lib/lib-signals.c @@ -95,7 +95,8 @@ static void sig_handler(int signo, siginfo_t *si, void *context ATTR_UNUSED) return; /* remember that we're inside a signal handler which might have been - called at any time. don't do anything that's unsafe. */ + called at any time. don't do anything that's unsafe. we might also + get interrupted by another signal while inside this handler. */ for (h = signal_handlers[signo]; h != NULL; h = h->next) { if (!h->delayed) h->handler(si, h->context); @@ -125,7 +126,7 @@ static void signal_read(void *context ATTR_UNUSED) siginfo_t signals[MAX_SIGNAL_VALUE+1]; sigset_t fullset, oldset; struct signal_handler *h; - char buf[2]; + char buf[64]; int signo; ssize_t ret; @@ -134,8 +135,9 @@ static void signal_read(void *context ATTR_UNUSED) if (sigprocmask(SIG_BLOCK, &fullset, &oldset) < 0) i_fatal("sigprocmask() failed: %m"); + /* typically we should read only a single byte, but if a signal + is sent while signal handler is running we might get more. */ ret = read(sig_pipe_fd[0], buf, sizeof(buf)); - i_assert(ret <= 1); if (ret > 0) { memcpy(signals, pending_signals, sizeof(signals)); memset(pending_signals, 0, sizeof(pending_signals));