From 82f556b5290b7fa9b39e07af99d841c6aaa323ab Mon Sep 17 00:00:00 2001 From: "Alan T. DeKok" Date: Sun, 25 Sep 2016 11:06:11 -0400 Subject: [PATCH] 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. --- src/include/radiusd.h | 2 ++ src/main/connection.c | 14 ++++++++++++++ src/main/process.c | 8 ++++++++ 3 files changed, 24 insertions(+) diff --git a/src/include/radiusd.h b/src/include/radiusd.h index df9dbc0..379d587 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 2df1619..81c8963 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 @@ -1405,6 +1410,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 */ this = fr_connection_find(pool, conn); diff --git a/src/main/process.c b/src/main/process.c index 741e5aa..e19752d 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. */ -- 2.1.4