[Fedora-directory-commits] ldapserver/ldap/servers/snmp ldap-agent.c, 1.9, 1.10 ldap-agent.h, 1.7, 1.8 main.c, 1.7, 1.8

Nathan Kinder (nkinder) fedora-directory-commits at redhat.com
Thu Apr 13 23:12:19 UTC 2006


Author: nkinder

Update of /cvs/dirsec/ldapserver/ldap/servers/snmp
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv24599/ldap/servers/snmp

Modified Files:
	ldap-agent.c ldap-agent.h main.c 
Log Message:
188931 - Use system Net-SNMP libraries on Linux systems


Index: ldap-agent.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/snmp/ldap-agent.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- ldap-agent.c	19 Apr 2005 22:07:42 -0000	1.9
+++ ldap-agent.c	13 Apr 2006 23:12:16 -0000	1.10
@@ -115,7 +115,10 @@
     netsnmp_table_registration_info *ops_table_info = NULL;
     netsnmp_table_registration_info *entries_table_info = NULL;
     netsnmp_table_registration_info *entity_table_info = NULL;
+    /* This is a hacky way of figuring out if we are on Net-SNMP 5.2 or later */
+#ifdef NETSNMP_CACHE_AUTO_RELOAD
     netsnmp_cache *stats_table_cache = NULL;
+#endif
 
     if (ops_handler || entries_handler || entity_handler) {
         snmp_log(LOG_ERR, "initialize_stats_table called more than once.\n");
@@ -188,12 +191,19 @@
                                      entity_cb.container, 1);
 
     /* Setup cache for auto reloading of stats */
+#ifdef NETSNMP_CACHE_AUTO_RELOAD
+    /* This is new api as of Net-SNMP 5.2 */
     stats_table_cache = netsnmp_cache_create(CACHE_REFRESH_INTERVAL, load_stats_table,
                                             NULL, dsOpsTable_oid, dsOpsTable_oid_len);
     stats_table_cache->flags |= NETSNMP_CACHE_DONT_FREE_EXPIRED;
     stats_table_cache->flags |= NETSNMP_CACHE_DONT_AUTO_RELEASE;
     stats_table_cache->flags |= NETSNMP_CACHE_AUTO_RELOAD;
     netsnmp_inject_handler(ops_handler, netsnmp_cache_handler_get(stats_table_cache));
+#else
+    /* Do things the old way.  This is only needed for Net-SNMP 5.1 and earlier. */
+    netsnmp_inject_handler(ops_handler, netsnmp_get_cache_handler(CACHE_REFRESH_INTERVAL, load_stats_table,
+                                            free_stats_table, dsOpsTable_oid, dsOpsTable_oid_len));
+#endif
 }
 
 /************************************************************
@@ -264,7 +274,7 @@
     int stats_hdl = -1;
     int err;
 
-    snmp_log(LOG_DEBUG, "Reloading stats.\n");
+    snmp_log(LOG_INFO, "Reloading stats.\n");
 
     /* Initialize data for each server in conf file */
     for (serv_p = server_head; serv_p != NULL; serv_p = serv_p->next) {
@@ -274,7 +284,7 @@
             previous_state = serv_p->server_state;
             previous_start = ctx->hdr_tbl.startTime;
 
-            snmp_log(LOG_DEBUG, "Opening stats file (%s) for server: %d\n",
+            snmp_log(LOG_INFO, "Opening stats file (%s) for server: %d\n",
                      serv_p->stats_file, serv_p->port);
 
             /* Open the stats file */
@@ -342,6 +352,20 @@
 }
 
 /************************************************************
+ * free_stats_table
+ *
+ * This function doesn't need to free anything since the
+ * load_stats_table function doesn't allocate any memory
+ * itself.  The cache handler requires us to have a callback
+ * function for freeing the cache, so here it is.
+ */
+void
+free_stats_table(netsnmp_cache *cache, void *foo)
+{
+    return;
+}
+
+/************************************************************
  * dsOpsTable_get_value
  *
  * This routine is called for get requests to copy the data


Index: ldap-agent.h
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/snmp/ldap-agent.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ldap-agent.h	19 Apr 2005 22:07:42 -0000	1.7
+++ ldap-agent.h	13 Apr 2006 23:12:16 -0000	1.8
@@ -90,6 +90,7 @@
     void        init_ldap_agent(void);
     void        initialize_stats_table(void);
     int         load_stats_table(netsnmp_cache *, void *);
+    void        free_stats_table(netsnmp_cache *, void *);
     stats_table_context *stats_table_create_row(unsigned long);
     stats_table_context *stats_table_find_row(unsigned long);
     int         dsOpsTable_get_value(netsnmp_request_info *,


Index: main.c
===================================================================
RCS file: /cvs/dirsec/ldapserver/ldap/servers/snmp/main.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- main.c	19 Apr 2005 22:07:42 -0000	1.7
+++ main.c	13 Apr 2006 23:12:16 -0000	1.8
@@ -53,9 +53,9 @@
 RETSIGTYPE
 stop_server(int signum) {
     if (signum == SIGUSR1) {
-        snmp_log(LOG_INFO, "Detected attempt to start ldap-agent again.\n");
+        snmp_log(LOG_WARNING, "Detected attempt to start ldap-agent again.\n");
     } else {
-        snmp_log(LOG_INFO, "Received stop signal.  Stopping ldap-agent...\n");
+        snmp_log(LOG_WARNING, "Received stop signal.  Stopping ldap-agent...\n");
         keep_running = 0;
     }
 }
@@ -64,7 +64,7 @@
 main (int argc, char *argv[]) {
     char                *config_file = NULL;
     netsnmp_log_handler *log_hdl = NULL;
-    int                 c, log_level = LOG_INFO;
+    int                 c, log_level = LOG_WARNING;
     struct stat         logdir_s;
     pid_t               child_pid;
     FILE                *pid_fp;
@@ -149,13 +149,13 @@
             exit(1);
         } 
 
-        netsnmp_enable_filelog(log_hdl, 1);
+        snmp_enable_filelog((char*)log_hdl->token, 1);
     } else {
         printf("Error starting logging.");
         exit(1);
     }
 
-    snmp_log(LOG_INFO, "Starting ldap-agent...\n");
+    snmp_log(LOG_WARNING, "Starting ldap-agent...\n");
 
     /* setup agentx master */
     netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID,
@@ -204,7 +204,7 @@
     }
 
     /* we're up and running! */
-    snmp_log(LOG_INFO, "Started ldap-agent as pid %d\n", child_pid);
+    snmp_log(LOG_WARNING, "Started ldap-agent as pid %d\n", child_pid);
 
     /* loop here until asked to stop */
     while(keep_running) {
@@ -213,7 +213,7 @@
 
     /* say goodbye */
     snmp_shutdown("ldap-agent");
-    snmp_log(LOG_INFO, "ldap-agent stopped.\n");
+    snmp_log(LOG_WARNING, "ldap-agent stopped.\n");
 
     /* remove pidfile */ 
     remove(pidfile);




More information about the Fedora-directory-commits mailing list