On Wed, 17 Jan 2007 06:17:54 +0100 Thomas wrote:
TA> > Yeah. But, since Thomas wants to see what would be required to hack it, 
here
TA> > is patch that would sever the explicit dependency between the agent and
TA> > helpers libraries.
TA> 
TA> Yep and you have my full understanding for not attaching it. ;-)

D'oh!  Note that this patch doesn't include moving the 3 required helper
modules, but simply deals with moving the explicit library init call from the
agent library into the application.

TA> > - Applications that need the helper library would need to call the new 
init
TA> > function. i.e. this introduces a break in backwards compatibility. 
TA> 
TA> Are you sure there isn't a way around? Can't we *duplicate* the most basic
TA> handlers in the agent library (under slightly different names) and adjust 
*our*
TA> code to make use of it, much like we did with make_tempfile/netsnmp_mktemp? 
But
TA> I haven't seen your patch yet, so I'm just wild-guessing, currently.

Well, I found some info on library init/constructor functions, but I'm not
sure how portable it would be, nor if it would be possible to affect the order
they were called when multiple libraries are involved. See section 5.2 here:
   http://howtos.linux.com/howtos/Program-Library-HOWTO/miscellaneous.shtml

If the 3 helpers I mentioned were moved into the agent library, it becomes
possible that existing applications that are linked against the helpers
library but aren't using any other helpers might, depending on the OS and link
options, not ever load the library.

The other option would be to:

- very carefully examine every public/exported function in every helper which
isn't moved into the agent library

- determine which functions expect/require that the helper's init function was
called

- modify those functions to conditionally call the helper's init function if a
static need_init flag is set.

Index: agent/snmp_vars.c
===================================================================
RCS file: /cvsroot/net-snmp/net-snmp/agent/snmp_vars.c,v
retrieving revision 5.29
diff -u -p -r5.29 snmp_vars.c
--- agent/snmp_vars.c	15 Sep 2006 00:48:39 -0000	5.29
+++ agent/snmp_vars.c	16 Jan 2007 23:44:55 -0000
@@ -304,7 +304,14 @@ init_agent(const char *app)
 
     _init_agent_callback_transport();
     
-    netsnmp_init_helpers();
+    /*
+     * Since someone might want to build an agent with no helpers, don't
+     * explicitly call the helpers init (which would create a dependency).
+     * Instead, call a 'init helpers' callback. The application must call
+     * netsnmp_init_helpers() to set up the callback.
+     */
+    snmp_call_callbacks(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_DEPENDENCY_INIT,
+                        (void *)'help');
     init_traps();
     netsnmp_container_init_list();
 
Index: agent/snmpd.c
===================================================================
RCS file: /cvsroot/net-snmp/net-snmp/agent/snmpd.c,v
retrieving revision 5.75
diff -u -p -r5.75 snmpd.c
--- agent/snmpd.c	18 Oct 2006 01:46:16 -0000	5.75
+++ agent/snmpd.c	16 Jan 2007 23:44:56 -0000
@@ -490,6 +490,12 @@ main(int argc, char *argv[])
 
     netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID,
                        NETSNMP_DS_AGENT_CACHE_TIMEOUT, 5);
+
+    /*
+     * set up libraries for callbacks
+     */
+    netsnmp_init_helpers();
+
     /*
      * Add some options if they are available.  
      */
Index: agent/helpers/all_helpers.c
===================================================================
RCS file: /cvsroot/net-snmp/net-snmp/agent/helpers/all_helpers.c,v
retrieving revision 5.9
diff -u -p -r5.9 all_helpers.c
--- agent/helpers/all_helpers.c	9 Jan 2006 15:06:33 -0000	5.9
+++ agent/helpers/all_helpers.c	16 Jan 2007 23:44:56 -0000
@@ -31,16 +31,29 @@ void  netsnmp_init_table_dataset(void);
 void  netsnmp_init_stash_cache_helper(void);
 #endif
 
+
 /** call the initialization sequence for all handlers with init_ routines. */
-void
-netsnmp_init_helpers(void)
+int
+_netsnmp_init_helpers_callback( int majorID, int minorID,
+                                void *serverarg, void *clientarg);
 {
+    if ( (void*)'help' != clientarg)
+        return 0;
+
     netsnmp_init_debug_helper();
     netsnmp_init_serialize();
     netsnmp_init_read_only_helper();
     netsnmp_init_bulk_to_next_helper();
     netsnmp_init_table_dataset();
     netsnmp_init_stash_cache_helper();
+    return 0;
+}
+
+void
+netsnmp_init_helpers(void) {
+    snmp_register_callback(SNMP_CALLBACK_LIBRARY,
+                           SNMP_CALLBACK_DEPENDENCY_INIT, _netsnmp_init_helpers_callback,
+                           NULL);
 }
 
 /** @defgroup utilities utility_handlers
Index: include/net-snmp/library/callback.h
===================================================================
RCS file: /cvsroot/net-snmp/net-snmp/include/net-snmp/library/callback.h,v
retrieving revision 5.4
diff -u -p -r5.4 callback.h
--- include/net-snmp/library/callback.h	21 Apr 2005 14:26:10 -0000	5.4
+++ include/net-snmp/library/callback.h	16 Jan 2007 23:45:02 -0000
@@ -27,6 +27,7 @@ extern          "C" {
 #define SNMP_CALLBACK_POST_PREMIB_READ_CONFIG	3
 #define SNMP_CALLBACK_LOGGING			4
 #define SNMP_CALLBACK_SESSION_INIT		5
+#define SNMP_CALLBACK_DEPENDENCY_INIT		6
 
 
     /*
-------------------------------------------------------------------------
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