Create new mutex for Access-Challenge debug code.
authorAlan T. DeKok <aland@freeradius.org>
Fri, 27 Aug 2010 10:48:14 +0000 (12:48 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 27 Aug 2010 10:49:15 +0000 (12:49 +0200)
This prevents the recursive mutex problem on some platforms.

src/modules/rlm_eap/mem.c
src/modules/rlm_eap/rlm_eap.c
src/modules/rlm_eap/rlm_eap.h

index 5bdf633..e0f4c6b 100644 (file)
@@ -120,9 +120,9 @@ EAP_HANDLER *eap_handler_alloc(rlm_eap_t *inst)
        memset(handler, 0, sizeof(EAP_HANDLER));
 
        if (fr_debug_flag && inst->handler_tree) {
-               pthread_mutex_lock(&(inst->session_mutex));
+               pthread_mutex_lock(&(inst->handler_mutex));
                rbtree_insert(inst->handler_tree, handler);
-               pthread_mutex_unlock(&(inst->session_mutex));
+               pthread_mutex_unlock(&(inst->handler_mutex));
        
        }
        return handler;
@@ -134,9 +134,9 @@ void eap_handler_free(rlm_eap_t *inst, EAP_HANDLER *handler)
                return;
 
        if (inst->handler_tree) {
-               pthread_mutex_lock(&(inst->session_mutex));
+               pthread_mutex_lock(&(inst->handler_mutex));
                rbtree_deletebydata(inst->handler_tree, handler);
-               pthread_mutex_unlock(&(inst->session_mutex));
+               pthread_mutex_unlock(&(inst->handler_mutex));
        }
 
        if (handler->identity) {
index 7424a52..9bcda21 100644 (file)
@@ -66,6 +66,7 @@ static int eap_detach(void *instance)
        }
 
        pthread_mutex_destroy(&(inst->session_mutex));
+       if (fr_debug_flag) pthread_mutex_destroy(&(inst->handler_mutex));
 
        free(inst);
 
@@ -255,9 +256,19 @@ static int eap_instantiate(CONF_SECTION *cs, void **instance)
                        eap_detach(inst);
                        return -1;
                }
+
+               if (pthread_mutex_init(&(inst->handler_mutex), NULL) < 0) {
+                       radlog(L_ERR|L_CONS, "rlm_eap: Failed initializing mutex: %s", strerror(errno));
+                       eap_detach(inst);
+                       return -1;
+               }
        }
 
-       pthread_mutex_init(&(inst->session_mutex), NULL);
+       if (pthread_mutex_init(&(inst->session_mutex), NULL) < 0) {
+               radlog(L_ERR|L_CONS, "rlm_eap: Failed initializing mutex: %s", strerror(errno));
+               eap_detach(inst);
+               return -1;
+       }
 
        *instance = inst;
        return 0;
index 4802db7..84b4b50 100644 (file)
@@ -66,6 +66,7 @@ typedef struct rlm_eap_t {
 
 #ifdef HAVE_PTHREAD_H
        pthread_mutex_t session_mutex;
+       pthread_mutex_t handler_mutex;
 #endif
 
        const char      *xlat_name; /* no xlat's yet */