[389-commits] ldap/servers

Noriko Hosoi nhosoi at fedoraproject.org
Fri Jan 31 18:32:30 UTC 2014


 ldap/servers/slapd/libglobs.c      |    2 
 ldap/servers/slapd/snmp_collator.c |   89 ++++++++++++++++++-------------------
 2 files changed, 46 insertions(+), 45 deletions(-)

New commits:
commit 03533f254530307ab6b831e1e1a9d7e7d41711f7
Author: Noriko Hosoi <nhosoi at redhat.com>
Date:   Thu Jan 30 17:57:09 2014 -0800

    Ticket #47570 - slapi_ldap_init unusable during independent plugin development
    
    Description:
    RFE: making slapi_ldap_init callable without snmp_collator_init.
    The api slapi_ldap_init calls set_snmp_interaction_row, in which
    interaction_table_mutex is held.  This patch replaces NSPR PR_(Un)Lock with
    slapi_(un)lock_mutex.  The slapi_(un)lock_mutex skips locking if the mutex
    is not initialized.
    
    https://fedorahosted.org/389/ticket/47570
    
    Reviewed by rmeggins at redhat.com (Thank you, Rich!!)

diff --git a/ldap/servers/slapd/libglobs.c b/ldap/servers/slapd/libglobs.c
index e887ace..7ef06a8 100644
--- a/ldap/servers/slapd/libglobs.c
+++ b/ldap/servers/slapd/libglobs.c
@@ -1556,7 +1556,7 @@ void libldap_init_debug_level(int *val_ptr)
 }
 #endif
 
-struct snmp_vars_t global_snmp_vars;
+static struct snmp_vars_t global_snmp_vars;
 
 struct snmp_vars_t * g_get_global_snmp_vars(){
     return &global_snmp_vars;
diff --git a/ldap/servers/slapd/snmp_collator.c b/ldap/servers/slapd/snmp_collator.c
index 4724b6f..f33202d 100644
--- a/ldap/servers/slapd/snmp_collator.c
+++ b/ldap/servers/slapd/snmp_collator.c
@@ -117,8 +117,8 @@ static Slapi_Eq_Context snmp_eq_ctx;
 static int snmp_collator_stopped = 0;
 
 /* synchronization stuff */
-static PRLock 		*interaction_table_mutex;
-static sem_t		*stats_sem;
+static Slapi_Mutex *interaction_table_mutex = NULL;
+static sem_t		*stats_sem = NULL;
 
 
 /***********************************************************************************
@@ -129,7 +129,9 @@ static sem_t		*stats_sem;
 *
 ************************************************************************************/
 
-static int snmp_collator_init(){
+static int 
+snmp_collator_init()
+{
 	int i;
 
 	/*
@@ -207,7 +209,9 @@ static int snmp_collator_init(){
 	sem_post(stats_sem);
 
 	/* create lock for interaction table */
-        interaction_table_mutex = PR_NewLock();
+	if (!interaction_table_mutex) {
+		interaction_table_mutex = slapi_new_mutex();
+	}
 
 	return 0;
 }
@@ -224,7 +228,7 @@ static int snmp_collator_init(){
 void set_snmp_interaction_row(char *host, int port, int error)
 {
   int index;
-  int isnew;
+  int isnew = 0;
   char *dsName;
   char *dsURL;
 
@@ -239,43 +243,42 @@ void set_snmp_interaction_row(char *host, int port, int error)
   dsURL= make_ds_url(host, port);
 
   /* lock around here to avoid race condition of two threads trying to update table at same time */
-  PR_Lock(interaction_table_mutex);     
-      index = search_interaction_table(dsURL, &isnew);
-  
-      if(isnew){
-          /* fillin the new row from scratch*/
-          g_get_global_snmp_vars()->int_tbl[index].dsIntIndex	                  = index;
-          strncpy(g_get_global_snmp_vars()->int_tbl[index].dsName, dsName,
-                  sizeof(g_get_global_snmp_vars()->int_tbl[index].dsName));
-          g_get_global_snmp_vars()->int_tbl[index].dsTimeOfCreation	          = time(0);
-          g_get_global_snmp_vars()->int_tbl[index].dsTimeOfLastAttempt	          = time(0);
-          if(error == 0){
-              g_get_global_snmp_vars()->int_tbl[index].dsTimeOfLastSuccess	  = time(0);
-              g_get_global_snmp_vars()->int_tbl[index].dsFailuresSinceLastSuccess = 0;
-              g_get_global_snmp_vars()->int_tbl[index].dsFailures	          = 0;
-              g_get_global_snmp_vars()->int_tbl[index].dsSuccesses		  = 1;
-          }else{
-              g_get_global_snmp_vars()->int_tbl[index].dsTimeOfLastSuccess	  = 0;
-              g_get_global_snmp_vars()->int_tbl[index].dsFailuresSinceLastSuccess = 1;
-              g_get_global_snmp_vars()->int_tbl[index].dsFailures		  = 1;
-              g_get_global_snmp_vars()->int_tbl[index].dsSuccesses		  = 0;
-          }
-          strncpy(g_get_global_snmp_vars()->int_tbl[index].dsURL, dsURL,
-                  sizeof(g_get_global_snmp_vars()->int_tbl[index].dsURL));		         
+  slapi_lock_mutex(interaction_table_mutex);
+  index = search_interaction_table(dsURL, &isnew);
+  if(isnew){
+      /* fillin the new row from scratch*/
+      g_get_global_snmp_vars()->int_tbl[index].dsIntIndex	                  = index;
+      strncpy(g_get_global_snmp_vars()->int_tbl[index].dsName, dsName,
+              sizeof(g_get_global_snmp_vars()->int_tbl[index].dsName));
+      g_get_global_snmp_vars()->int_tbl[index].dsTimeOfCreation	          = time(0);
+      g_get_global_snmp_vars()->int_tbl[index].dsTimeOfLastAttempt	          = time(0);
+      if(error == 0){
+          g_get_global_snmp_vars()->int_tbl[index].dsTimeOfLastSuccess	  = time(0);
+          g_get_global_snmp_vars()->int_tbl[index].dsFailuresSinceLastSuccess = 0;
+          g_get_global_snmp_vars()->int_tbl[index].dsFailures	          = 0;
+          g_get_global_snmp_vars()->int_tbl[index].dsSuccesses		  = 1;
       }else{
-        /* just update the appropriate fields */
-           g_get_global_snmp_vars()->int_tbl[index].dsTimeOfLastAttempt	         = time(0);
-          if(error == 0){
-             g_get_global_snmp_vars()->int_tbl[index].dsTimeOfLastSuccess        = time(0);
-             g_get_global_snmp_vars()->int_tbl[index].dsFailuresSinceLastSuccess = 0;
-             g_get_global_snmp_vars()->int_tbl[index].dsSuccesses                += 1;
-          }else{
-             g_get_global_snmp_vars()->int_tbl[index].dsFailuresSinceLastSuccess +=1;
-             g_get_global_snmp_vars()->int_tbl[index].dsFailures                 +=1;
-          }
-
+          g_get_global_snmp_vars()->int_tbl[index].dsTimeOfLastSuccess	  = 0;
+          g_get_global_snmp_vars()->int_tbl[index].dsFailuresSinceLastSuccess = 1;
+          g_get_global_snmp_vars()->int_tbl[index].dsFailures		  = 1;
+          g_get_global_snmp_vars()->int_tbl[index].dsSuccesses		  = 0;
       }
-  PR_Unlock(interaction_table_mutex);     
+      strncpy(g_get_global_snmp_vars()->int_tbl[index].dsURL, dsURL,
+              sizeof(g_get_global_snmp_vars()->int_tbl[index].dsURL));		         
+  }else{
+    /* just update the appropriate fields */
+       g_get_global_snmp_vars()->int_tbl[index].dsTimeOfLastAttempt	         = time(0);
+      if(error == 0){
+         g_get_global_snmp_vars()->int_tbl[index].dsTimeOfLastSuccess        = time(0);
+         g_get_global_snmp_vars()->int_tbl[index].dsFailuresSinceLastSuccess = 0;
+         g_get_global_snmp_vars()->int_tbl[index].dsSuccesses                += 1;
+      }else{
+         g_get_global_snmp_vars()->int_tbl[index].dsFailuresSinceLastSuccess +=1;
+         g_get_global_snmp_vars()->int_tbl[index].dsFailures                 +=1;
+      }
+
+  }
+  slapi_unlock_mutex(interaction_table_mutex);
   /* free the memory allocated for dsURL in call to ds_make_url */
   if(dsURL != NULL){
     slapi_ch_free( (void**)&dsURL );
@@ -298,8 +301,8 @@ static char *make_ds_url(char *host, int port){
    return url;
 }
 
-
 /***********************************************************************************
+ * search_interaction_table is not used.
  * searches the table for the url specified 
  * If there, returns index to update stats
  * if, not there returns index of oldest interaction, and isnew flag is set
@@ -512,9 +515,7 @@ int snmp_collator_stop()
    sem_unlink(stats_sem_name);
 
    /* delete lock */
-   if (interaction_table_mutex) {
-       PR_DestroyLock(interaction_table_mutex);
-   }
+   slapi_destroy_mutex(interaction_table_mutex);
 
 #ifdef _WIN32
    /* send the event so server down trap gets set on NT */




More information about the 389-commits mailing list