* A mapping of configuration file names to internal integers
*/
static const CONF_PARSER thread_config[] = {
- { "start_servers", PW_TYPE_INTEGER, 0, &thread_pool.start_threads, "5" },
- { "max_servers", PW_TYPE_INTEGER, 0, &thread_pool.max_threads, "32" },
- { "min_spare_servers", PW_TYPE_INTEGER, 0, &thread_pool.min_spare_threads, "3" },
- { "max_spare_servers", PW_TYPE_INTEGER, 0, &thread_pool.max_spare_threads, "10" },
- { "max_requests_per_server", PW_TYPE_INTEGER, 0, &thread_pool.max_requests_per_thread, "0" },
- { "cleanup_delay", PW_TYPE_INTEGER, 0, &thread_pool.cleanup_delay, "5" },
+ { "start_servers", PW_TYPE_INTEGER, 0, &thread_pool.start_threads, "5" },
+ { "max_servers", PW_TYPE_INTEGER, 0, &thread_pool.max_threads, "32" },
+ { "min_spare_servers", PW_TYPE_INTEGER, 0, &thread_pool.min_spare_threads, "3" },
+ { "max_spare_servers", PW_TYPE_INTEGER, 0, &thread_pool.max_spare_threads, "10" },
+ { "max_requests_per_server", PW_TYPE_INTEGER, 0, &thread_pool.max_requests_per_thread, "0" },
+ { "cleanup_delay", PW_TYPE_INTEGER, 0, &thread_pool.cleanup_delay, "5" },
{ NULL, -1, 0, NULL, NULL }
};
struct timeval tv;
#ifdef HAVE_PTHREAD_SIGMASK
sigset_t set, old_set;
-
+
/*
* Block a large number of signals which could
* cause the select to return EINTR
for (count = 0; count < 10; count++) {
tv.tv_sec = 0;
tv.tv_usec = 10000; /* sleep for 10 milliseconds */
-
+
/*
* Portable sleep that's thread-safe.
*
ok = TRUE;
break;
}
- }
+ }
#ifdef HAVE_PTHREAD_SIGMASK
/*
sigaddset(&set, SIGTERM);
pthread_sigmask(SIG_BLOCK, &set, NULL);
#endif
-
+
/*
* Loop forever, until told to exit.
*/
DEBUG2("Thread %d handling request %d, (%d handled so far)",
self->thread_num, self->request->number,
self->request_count);
-
+
/*
* Respond, and reset request->child_pid
*/
} else {
prev->next = next;
}
-
+
if (next == NULL) {
rad_assert(thread_pool.tail == handle);
thread_pool.tail = prev;
*/
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-
+
/*
* Create the thread detached, so that it cleans up it's
* own memory when it exits.
* until all threads are finished handling requests. This returns
* the number of active threads to 'radiusd.c'.
*/
-int total_active_threads(void)
+int total_active_threads(void)
{
int rcode = 0;
THREAD_HANDLE *handle;
-
+
for (handle = thread_pool.head; handle != NULL; handle = handle->next){
if (handle->request != NULL) {
rcode ++;
*/
if (thread_pool.active_threads == thread_pool.total_threads) {
if (spawn_thread(request->timestamp) == NULL) {
- radlog(L_INFO,
- "The maximum number of threads (%d) are active, cannot spawn new thread to handle request",
+ radlog(L_INFO,
+ "The maximum number of threads (%d) are active, cannot spawn new thread to handle request",
thread_pool.max_threads);
return 0;
}
}
}
}
-
+
/*
* Otherwise everything's kosher. There are not too few,
* or too many spare threads. Exit happily.
void rad_exec_init(void)
{
int i;
-
+
/*
* Initialize the mutex used to remember calls to fork.
*/
pthread_mutex_init(&fork_mutex, NULL);
-
+
/*
* Initialize the data structure where we remember the
* mappings of thread ID && child PID to exit status.
pid_t rad_fork(int exec_wait)
{
sigset_t set;
- pid_t child_pid;
+ pid_t child_pid;
/*
* The thread is NOT interested in waiting for the exit
*/
i = PID_2_ARRAY(child_pid);
found = -1;
-
+
/*
* We may have multiple threads trying to find an
* empty position, so we lock the array until
* That is, we've forked, and the forker
* is waiting nearly forever
*/
- return 0;
+ return 0;
}
i++;