From: Alan T. DeKok Date: Sun, 25 Sep 2016 15:06:11 +0000 (-0400) Subject: Don't open new connections when exiting. Addresses #1604. X-Git-Tag: release_3_0_12~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=82f556b5290b7fa9b39e07af99d841c6aaa323ab;p=thirdparty%2Ffreeradius-server.git Don't open new connections when exiting. Addresses #1604. When we a get a SIGTERM or SIGQUIT, mark "exiting", and stop returning new connections. Also, don't allow reconnection of existing connections. This should help with CTRL-C. --- diff --git a/src/include/radiusd.h b/src/include/radiusd.h index df9dbc0a3b5..379d58742a6 100644 --- a/src/include/radiusd.h +++ b/src/include/radiusd.h @@ -167,6 +167,8 @@ typedef struct main_config { bool write_pid; //!< write the PID file + bool exiting; //!< are we exiting? + #ifdef ENABLE_OPENSSL_VERSION_CHECK char const *allow_vulnerable_openssl; //!< The CVE number of the last security issue acknowledged. diff --git a/src/main/connection.c b/src/main/connection.c index 2df16196192..81c89635d59 100644 --- a/src/main/connection.c +++ b/src/main/connection.c @@ -784,6 +784,11 @@ static void *fr_connection_get_internal(fr_connection_pool_t *pool, bool spawn) if (!pool) return NULL; + /* + * Allow CTRL-C to kill the server in debugging mode. + */ + if (main_config.exiting) return NULL; + #ifdef HAVE_PTHREAD_H if (spawn) pthread_mutex_lock(&pool->mutex); #endif @@ -1404,6 +1409,15 @@ void *fr_connection_reconnect(fr_connection_pool_t *pool, void *conn) if (!pool || !conn) return NULL; + /* + * Don't allow opening of new connections if we're trying + * to exit. + */ + if (main_config.exiting) { + fr_connection_release(pool, conn); + return NULL; + } + /* * If fr_connection_find is successful the pool is now locked */ diff --git a/src/main/process.c b/src/main/process.c index 741e5aa5528..e19752d255f 100644 --- a/src/main/process.c +++ b/src/main/process.c @@ -5164,6 +5164,10 @@ static void handle_signal_self(int flag) #ifndef HAVE_PTHREAD_H void radius_signal_self(int flag) { + if (flag == RADIUS_SIGNAL_SELF_TERM) { + main_config.exiting = true; + } + return handle_signal_self(flag); } @@ -5178,6 +5182,10 @@ void radius_signal_self(int flag) ssize_t rcode; uint8_t buffer[16]; + if (flag == RADIUS_SIGNAL_SELF_TERM) { + main_config.exiting = true; + } + /* * The read MUST be non-blocking for this to work. */