From aa4918c25bbb46b353d19d19180242196338c866 Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Fri, 2 Mar 2007 09:48:31 +0000 Subject: [PATCH] exit on signal, compatible with bad versions of libevent. git-svn-id: file:///svn/unbound/trunk@161 be551aaa-1e26-0410-a405-d3ace91eadb9 --- configure.ac | 5 +++++ daemon/daemon.c | 3 +++ daemon/worker.c | 2 ++ doc/Changelog | 3 +++ doc/README | 7 +++++++ 5 files changed, 20 insertions(+) diff --git a/configure.ac b/configure.ac index 5af6e6bed..5961a2c13 100644 --- a/configure.ac +++ b/configure.ac @@ -421,6 +421,7 @@ if test x_$withval != x_no; then AC_SEARCH_LIBS(event_set, [event]) AC_CHECK_HEADERS([event.h],,, [AC_INCLUDES_DEFAULT]) AC_CHECK_FUNCS([event_base_free]) # only in libevent 1.2 and later + AC_CHECK_FUNCS([event_base_once]) # only in libevent 1.4? and later else AC_DEFINE(USE_MINI_EVENT, 1, [Define if you want to use internal select based events]) fi @@ -519,6 +520,10 @@ AH_BOTTOM([ #define fseeko fseek #define ftello ftell #endif /* HAVE_FSEEKO */ +#if defined(HAVE_EVENT_H) && !defined(HAVE_EVENT_BASE_ONCE) && (defined(HAVE_PTHREAD) || defined(HAVE_SOLARIS_THREADS)) + /* using version of libevent that is not threadsafe. */ +# define LIBEVENT_SIGNAL_PROBLEM 1 +#endif #ifndef RAND_MAX #define RAND_MAX 2147483647 diff --git a/daemon/daemon.c b/daemon/daemon.c index aac6ac6a3..2b32e26af 100644 --- a/daemon/daemon.c +++ b/daemon/daemon.c @@ -59,6 +59,9 @@ static int sig_record_reload = 0; * when multiple signals in quick succession are sent to us. */ static RETSIGTYPE record_sigh(int sig) { +#ifdef LIBEVENT_SIGNAL_PROBLEM + exit(0); +#endif switch(sig) { case SIGTERM: diff --git a/daemon/worker.c b/daemon/worker.c index cfaf0c9cc..6e68902fb 100644 --- a/daemon/worker.c +++ b/daemon/worker.c @@ -323,6 +323,7 @@ worker_init(struct worker* worker, struct config_file *cfg, ub_thread_sig_unblock(SIGINT); ub_thread_sig_unblock(SIGQUIT); ub_thread_sig_unblock(SIGTERM); +#ifndef LIBEVENT_SIGNAL_PROBLEM worker->comsig = comm_signal_create(worker->base, worker_sighandler, worker); if(!worker->comsig || !comm_signal_bind(worker->comsig, SIGHUP) @@ -333,6 +334,7 @@ worker_init(struct worker* worker, struct config_file *cfg, worker_delete(worker); return 0; } +#endif /* LIBEVENT_SIGNAL_PROBLEM */ } else { /* !do_sigs */ worker->comsig = 0; } diff --git a/doc/Changelog b/doc/Changelog index fb3caacf3..b9c215125 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -2,6 +2,9 @@ - do not compile fork funcs unless needed. Otherwise will give type errors as their typedefs have not been enabled. - log shows thread numbers much more nicely (and portably). + - even on systems with nonthreadsafe libevent signal handling, + unbound will exit if given a signal. + Reloads will not work, and exit is not graceful. 1 March 2007: Wouter - Signals, libevent and threads work well, with libevent patch and diff --git a/doc/README b/doc/README index f701058e7..c1bb61b83 100644 --- a/doc/README +++ b/doc/README @@ -18,4 +18,11 @@ This software is under BSD license, see LICENSE for details. * run libtoolize -c if config.sub is missing. * autoreconf (autoheader && autoconf), if ./configure is missing. +Known issues +------------ +o If libevent is older (1.3 and before), unbound will exit instead of reload + on sighup. On a restart 'did not exit gracefully last time' warning is + printed. Perform ./configure --with-libevent=no or update libevent, rerun + configure and recompile unbound to make sighup work correctly. + * mailto:wouter@nlnetlabs.nl