Don't bother locking the FD ourselves, as it appears to cause
authoraland <aland>
Fri, 24 May 2002 17:31:23 +0000 (17:31 +0000)
committeraland <aland>
Fri, 24 May 2002 17:31:23 +0000 (17:31 +0000)
locks on some platforms.

Instead, don't lock it, but declare the module to be single threaded.

src/modules/rlm_counter/rlm_counter.c

index bc1bd1e..0ee2040 100644 (file)
@@ -130,9 +130,7 @@ static int counter_cmp(void *instance, REQUEST *req, VALUE_PAIR *request, VALUE_
        key_datum.dptr = key_vp->strvalue;
        key_datum.dsize = key_vp->length;
 
-       if (data->fd >= 0) rad_lockfd(data->fd, sizeof(int));
        count_datum = gdbm_fetch(data->gdbm, key_datum);
-       if (data->fd >= 0) rad_unlockfd(data->fd, sizeof(int));
 
        if (count_datum.dptr == NULL) {
                return -1;
@@ -430,7 +428,6 @@ static int counter_accounting(void *instance, REQUEST *request)
        key_datum.dptr = key_vp->strvalue;
        key_datum.dsize = key_vp->length;
 
-       if (data->fd >= 0) rad_lockfd(data->fd, sizeof(int));
        count_datum = gdbm_fetch(data->gdbm, key_datum);
        if (count_datum.dptr == NULL)
                counter = 0;
@@ -471,7 +468,6 @@ static int counter_accounting(void *instance, REQUEST *request)
        count_datum.dsize = sizeof(int);
 
        rcode = gdbm_store(data->gdbm, key_datum, count_datum, GDBM_REPLACE);
-       if (data->fd >= 0) rad_unlockfd(data->fd, sizeof(int));
        if (rcode < 0) {
                radlog(L_ERR, "rlm_counter: Failed storing data to %s: %s",
                                data->filename, gdbm_strerror(gdbm_errno));
@@ -560,9 +556,7 @@ static int counter_authorize(void *instance, REQUEST *request)
        key_datum.dptr = key_vp->strvalue;
        key_datum.dsize = key_vp->length;
        
-       if (data->fd >= 0) rad_lockfd(data->fd, sizeof(int));
        count_datum = gdbm_fetch(data->gdbm, key_datum);
-       if (data->fd >= 0) rad_unlockfd(data->fd, sizeof(int));
        if (count_datum.dptr != NULL){
                memcpy(&counter, count_datum.dptr, sizeof(int));
                free(count_datum.dptr);
@@ -666,7 +660,7 @@ static int counter_detach(void *instance)
  */
 module_t rlm_counter = {
        "Counter",      
-       RLM_TYPE_THREAD_SAFE,           /* type */
+       RLM_TYPE_THREAD_UNSAFE,         /* type */
        NULL,                           /* initialization */
        counter_instantiate,            /* instantiation */
        {