Hello!

I am certain that there is some good reason and hope somebody could tell
me, but why is the AgentX master module initiated by a separate call to
real_init_agentx in snmp_agent.c?

Or, expressed in another way, why is the below patch a bad idea?

Patch description:

* Applies to: trunk
* Use snmp_register_callback instead of a direct call to initialize the
  agentx code.
* Move the master agent code from libnetsnmpagent to libnetsnmpmibs

(Known drawbacks, the patch is a work in progress:
 * It will reparse the agentx config, possily it should handle
   duplicates there better)

/MF
Index: agent/mibgroup/agentx/master.h
===================================================================
--- agent/mibgroup/agentx/master.h	(revision 16014)
+++ agent/mibgroup/agentx/master.h	(working copy)
@@ -1,8 +1,6 @@
 #ifndef _AGENTX_MASTER_H
 #define _AGENTX_MASTER_H
 
-config_belongs_in(agent_module)
-
 config_require(agentx/protocol)
 config_require(agentx/client)
 config_require(agentx/master_admin)
@@ -10,7 +8,6 @@ config_require(agentx/agentx_config)
 config_require(mibII/sysORTable)
 
      void            init_master(void);
-     void            real_init_master(void);
      Netsnmp_Node_Handler agentx_master_handler;
 
 #endif                          /* _AGENTX_MASTER_H */
Index: agent/mibgroup/agentx/master_admin.h
===================================================================
--- agent/mibgroup/agentx/master_admin.h	(revision 16014)
+++ agent/mibgroup/agentx/master_admin.h	(working copy)
@@ -1,8 +1,6 @@
 #ifndef _AGENTX_MASTER_ADMIN_H
 #define _AGENTX_MASTER_ADMIN_H
 
-config_belongs_in(agent_module)
-
 int             handle_master_agentx_packet(int, netsnmp_session *,
                                             int, netsnmp_pdu *, void *);
 
Index: agent/mibgroup/agentx/master.c
===================================================================
--- agent/mibgroup/agentx/master.c	(revision 16014)
+++ agent/mibgroup/agentx/master.c	(working copy)
@@ -53,7 +53,7 @@
 #include "agentx/protocol.h"
 #include "agentx/master_admin.h"
 
-void
+static void
 real_init_master(void)
 {
     netsnmp_session sess, *session = NULL;
@@ -208,6 +208,14 @@ real_init_master(void)
     DEBUGMSGTL(("agentx/master", "initializing...   DONE\n"));
 }
 
+
+void init_master(void)
+{
+    snmp_register_callback(SNMP_CALLBACK_LIBRARY,
+			   SNMP_CALLBACK_POST_READ_CONFIG,
+			   &real_init_master, NULL);
+}
+
         /*
          * Handle the response from an AgentX subagent,
          *   merging the answers back into the original query
Index: agent/snmp_agent.c
===================================================================
--- agent/snmp_agent.c	(revision 16014)
+++ agent/snmp_agent.c	(working copy)
@@ -104,14 +104,6 @@ int             deny_severity = LOG_WARN
 #include <net-snmp/agent/mib_module_config.h>
 #include <net-snmp/agent/mib_modules.h>
 
-#ifdef USING_AGENTX_PROTOCOL_MODULE
-#include "agentx/protocol.h"
-#endif
-
-#ifdef USING_AGENTX_MASTER_MODULE
-#include "agentx/master.h"
-#endif
-
 #ifdef USING_SMUX_MODULE
 #include "smux/smux.h"
 #endif
@@ -1170,11 +1162,6 @@ init_master_agent(void)
         
         return 0;               /*  No error if ! MASTER_AGENT  */
     }
-#ifdef USING_AGENTX_MASTER_MODULE
-    if (netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, 
-			       NETSNMP_DS_AGENT_AGENTX_MASTER) == 1)
-        real_init_master();
-#endif
 #ifdef USING_SMUX_MODULE
     if(should_init("smux"))
     real_init_smux();
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to