Removed need for global NO_SUCH_CHILD_PID
authorAlan T. DeKok <aland@freeradius.org>
Sun, 14 Sep 2008 14:00:58 +0000 (16:00 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 14 Sep 2008 14:00:58 +0000 (16:00 +0200)
src/include/radiusd.h
src/main/event.c
src/main/util.c

index b8f3ef3..524254b 100644 (file)
@@ -37,8 +37,6 @@ typedef struct auth_req REQUEST;
 
 #ifdef HAVE_PTHREAD_H
 #include       <pthread.h>
-typedef pthread_t child_pid_t;
-#define NO_SUCH_CHILD_PID (child_pid_t) (0)
 #endif
 
 #ifndef NDEBUG
@@ -192,7 +190,7 @@ struct auth_req {
        request_data_t          *data;
        RADCLIENT               *client;
 #ifdef HAVE_PTHREAD_H
-       child_pid_t             child_pid;
+       pthread_t               child_pid;
 #endif
        time_t                  timestamp;
        int                     number; /* internal server number */
index 715721b..87537a1 100644 (file)
@@ -69,6 +69,8 @@ static pthread_mutex_t        proxy_mutex;
 
 #define PTHREAD_MUTEX_LOCK if (have_children) pthread_mutex_lock
 #define PTHREAD_MUTEX_UNLOCK if (have_children) pthread_mutex_unlock
+
+static pthread_t NO_SUCH_CHILD_PID;
 #else
 /*
  *     This is easier than ifdef's throughout the code.
@@ -1033,9 +1035,9 @@ static void wait_a_bit(void *ctx)
                         *      conditions on this check.  But it's
                         *      just an error message, so that's OK.
                         */
-                       if (request->child_pid != NO_SUCH_CHILD_PID) {
-                               radlog(L_ERR, "WARNING: Unresponsive child (id %lu) for request %d, in module %s component %s",
-                              (unsigned long)request->child_pid, request->number,
+                       if (!pthread_equal(request->child_pid, NO_SUCH_CHILD_PID)) {
+                               radlog(L_ERR, "WARNING: Unresponsive child for request %d, in module %s component %s",
+                                      request->number,
                                       request->module ? request->module : "<server core>",
                                       request->component ? request->component : "<server core>");
                        }
@@ -2210,6 +2212,9 @@ int received_request(rad_listen_t *listener,
        request->packet->timestamp = request->timestamp;
        request->number = request_num_counter++;
        request->priority = listener->type;
+#ifdef HAVE_PTHREAD_H
+       request->child_pid = NO_SUCH_CHILD_PID;
+#endif
 
        /*
         *      Status-Server packets go to the head of the queue.
@@ -2808,6 +2813,11 @@ int radius_event_init(CONF_SECTION *cs, int spawn_flag)
        if (spawn_flag) force_log_reopen();
 
 #ifdef HAVE_PTHREAD_H
+#ifndef __MINGW32__
+       NO_SUCH_CHILD_PID = (pthread_t ) (0);
+#else
+       NO_SUCH_CHILD_PID = pthread_self(); /* not a child thread */
+#endif
        if (thread_pool_init(cs, spawn_flag) < 0) {
                exit(1);
        }
index d397b4f..9041c51 100644 (file)
@@ -371,9 +371,6 @@ REQUEST *request_alloc(void)
        request->username = NULL;
        request->password = NULL;
        request->timestamp = time(NULL);
-#ifdef HAVE_PTHREAD_H
-       request->child_pid = NO_SUCH_CHILD_PID;
-#endif
        request->options = RAD_REQUEST_OPTION_NONE;
 
        request->module = "";
@@ -398,7 +395,7 @@ REQUEST *request_alloc_fake(REQUEST *request)
 
   fake->number = request->number;
 #ifdef HAVE_PTHREAD_H
-  fake->child_pid = NO_SUCH_CHILD_PID;
+  fake->child_pid = request->child_pid;
 #endif
   fake->parent = request;
   fake->root = request->root;