Don't open new connections when exiting. Addresses #1604.
authorAlan T. DeKok <aland@freeradius.org>
Sun, 25 Sep 2016 15:06:11 +0000 (11:06 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 25 Sep 2016 15:06:11 +0000 (11:06 -0400)
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
src/main/connection.c
src/main/process.c

index df9dbc0..379d587 100644 (file)
@@ -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.
index 2df1619..81c8963 100644 (file)
@@ -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);
index 741e5aa..e19752d 100644 (file)
@@ -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.
         */