Made thread pool section optional
authorAlan T. DeKok <aland@freeradius.org>
Sun, 5 Jul 2009 08:02:05 +0000 (10:02 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 5 Jul 2009 08:02:05 +0000 (10:02 +0200)
If it doesn't exist, the server will run single threaded

src/include/radiusd.h
src/main/event.c
src/main/threads.c

index 6c84c2b..44d8f5a 100644 (file)
@@ -593,7 +593,7 @@ void                xlat_unregister(const char *module, RAD_XLAT_FUNC func);
 void           xlat_free(void);
 
 /* threads.c */
-extern         int thread_pool_init(CONF_SECTION *cs, int spawn_flag);
+extern         int thread_pool_init(CONF_SECTION *cs, int *spawn_flag);
 extern         int thread_pool_addrequest(REQUEST *, RAD_REQUEST_FUNP);
 extern         pid_t rad_fork(void);
 extern         pid_t rad_waitpid(pid_t pid, int *status);
index 86bd7cc..e3e946a 100644 (file)
@@ -3473,13 +3473,6 @@ int radius_event_init(CONF_SECTION *cs, int spawn_flag)
 
        request_num_counter = 0;
 
-       /*
-        *      Move all of the thread calls to this file?
-        *
-        *      It may be best for the mutexes to be in this file...
-        */
-       have_children = spawn_flag;
-
 #ifdef WITH_PROXY
        if (mainconfig.proxy_requests) {
                pthread_mutexattr_t attr;
@@ -3525,11 +3518,23 @@ int radius_event_init(CONF_SECTION *cs, int spawn_flag)
 #else
        NO_SUCH_CHILD_PID = pthread_self(); /* not a child thread */
 #endif
-       if (thread_pool_init(cs, spawn_flag) < 0) {
+       /*
+        *      Initialize the threads ONLY if we're spawning, AND
+        *      we're running normally.
+        */
+       if (spawn_flag && !check_config &&
+           (thread_pool_init(cs, &spawn_flag) < 0)) {
                exit(1);
        }
 #endif
 
+       /*
+        *      Move all of the thread calls to this file?
+        *
+        *      It may be best for the mutexes to be in this file...
+        */
+       have_children = spawn_flag;
+
        if (check_config) {
                DEBUG("%s: #### Skipping IP addresses and Ports ####",
                       mainconfig.name);
index 9ce78cb..51ffaa2 100644 (file)
@@ -693,7 +693,7 @@ static int pid_cmp(const void *one, const void *two)
  *
  *     FIXME: What to do on a SIGHUP???
  */
-int thread_pool_init(CONF_SECTION *cs, int spawn_flag)
+int thread_pool_init(CONF_SECTION *cs, int *spawn_flag)
 {
        int             i, rcode;
        CONF_SECTION    *pool_cf;
@@ -701,52 +701,48 @@ int thread_pool_init(CONF_SECTION *cs, int spawn_flag)
 
        now = time(NULL);
 
+       rad_assert(spawn_flag != NULL);
+       rad_assert(*spawn_flag == TRUE);
+       rad_assert(pool_initialized == FALSE); /* not called on HUP */
+
+       pool_cf = cf_subsection_find_next(cs, NULL, "thread");
+       if (!pool_cf) *spawn_flag = FALSE;
+
        /*
-        *      We're not spawning new threads, don't do
-        *      anything.
+        *      Initialize the thread pool to some reasonable values.
         */
-       if (!spawn_flag) return 0;
-
+       memset(&thread_pool, 0, sizeof(THREAD_POOL));
+       thread_pool.head = NULL;
+       thread_pool.tail = NULL;
+       thread_pool.total_threads = 0;
+       thread_pool.max_thread_num = 1;
+       thread_pool.cleanup_delay = 5;
+       thread_pool.spawn_flag = *spawn_flag;
+       
        /*
-        *      After a SIGHUP, we don't over-write the previous values.
+        *      Don't bother initializing the mutexes or
+        *      creating the hash tables.  They won't be used.
         */
-       if (!pool_initialized) {
-               /*
-                *      Initialize the thread pool to some reasonable values.
-                */
-               memset(&thread_pool, 0, sizeof(THREAD_POOL));
-               thread_pool.head = NULL;
-               thread_pool.tail = NULL;
-               thread_pool.total_threads = 0;
-               thread_pool.max_thread_num = 1;
-               thread_pool.cleanup_delay = 5;
-               thread_pool.spawn_flag = spawn_flag;
-
+       if (!*spawn_flag) return 0;
+       
 #ifdef WNOHANG
-               if ((pthread_mutex_init(&thread_pool.wait_mutex,NULL) != 0)) {
-                       radlog(L_ERR, "FATAL: Failed to initialize wait mutex: %s",
-                              strerror(errno));
-                       return -1;
-               }
-
-               /*
-                *      Create the hash table of child PID's
-                */
-               thread_pool.waiters = fr_hash_table_create(pid_hash,
-                                                            pid_cmp,
-                                                            free);
-               if (!thread_pool.waiters) {
-                       radlog(L_ERR, "FATAL: Failed to set up wait hash");
-                       return -1;
-               }
-#endif
+       if ((pthread_mutex_init(&thread_pool.wait_mutex,NULL) != 0)) {
+               radlog(L_ERR, "FATAL: Failed to initialize wait mutex: %s",
+                      strerror(errno));
+               return -1;
        }
-
-       pool_cf = cf_subsection_find_next(cs, NULL, "thread");
-       if (!pool_cf) {
-               radlog(L_ERR, "FATAL: Attempting to start in multi-threaded mode with no thread configuration in radiusd.conf");
+       
+       /*
+        *      Create the hash table of child PID's
+        */
+       thread_pool.waiters = fr_hash_table_create(pid_hash,
+                                                  pid_cmp,
+                                                  free);
+       if (!thread_pool.waiters) {
+               radlog(L_ERR, "FATAL: Failed to set up wait hash");
                return -1;
        }
+#endif
 
        if (cf_section_parse(pool_cf, NULL, thread_config) < 0) {
                return -1;