Hi,

finally, here are two proposed patches which remove mandatory logging to
stderr in snmpd if it is using subagents implemented in Perl. snmpd now
redirects its stderr to /dev/null as one would expect from a normal daemon,
unless the user explicitly asks for stderr logging.

Both of the attached patches fix my problem, but in completely different
ways. Feel free to use either one or both, depending on what you think is
the correct solution.

check-stderrlog-before-subagent-init.diff:
Removes calls to snmp_enable_stderrlog() from Perl module init code.
stderrlog gets enabled automatically when printing the first log message
with no other log destinations enabled, so these calls are redundant.
Automatically enabling stderrlog on the first message triggers an additional
log message about automatically enabling stderrlog, but that matches the
behaviour of snmpwalk etc., so I guess that's OK.

no-perlmod-enable-stderrlog.diff:
Checks whether stderrlog is enabled before initializing Perl subagents and
uses that information to decide whether to close stderr later on (after Perl
init) when daemonizing. This way, usage of stderr depends only on the
commandline options specified by the user, not on snmp_enable_stderrlog()
calls performed by other parts of the code.

Thanks for any feedback or applying the patches,
Martin
diff -ur net-snmp-5.6.1.orig/perl/SNMP/SNMP.xs net-snmp-5.6.1/perl/SNMP/SNMP.xs
--- net-snmp-5.6.1.orig/perl/SNMP/SNMP.xs	2010-12-01 00:27:48.000000000 +0100
+++ net-snmp-5.6.1/perl/SNMP/SNMP.xs	2011-01-25 18:39:23.000000000 +0100
@@ -231,7 +231,6 @@
         have_inited = 1;
 
         snmp_set_quick_print(1);
-        snmp_enable_stderrlog();
         init_snmp(appname);
     
         netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_BREAKDOWN_OIDS, 1);
diff -ur net-snmp-5.6.1.orig/perl/agent/agent.pm net-snmp-5.6.1/perl/agent/agent.pm
--- net-snmp-5.6.1.orig/perl/agent/agent.pm	2010-12-01 01:46:49.000000000 +0100
+++ net-snmp-5.6.1/perl/agent/agent.pm	2011-01-25 18:38:52.000000000 +0100
@@ -131,7 +131,6 @@
 	return if ($haveinit);
 	$haveinit = 1;
 
-	snmp_enable_stderrlog();
 	my $flags = $_[0];
 	if ($flags->{'AgentX'}) {
 	    netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE, 1);
diff -ur net-snmp-5.6.1.orig/agent/snmpd.c net-snmp-5.6.1/agent/snmpd.c
--- net-snmp-5.6.1.orig/agent/snmpd.c	2010-12-01 02:06:05.000000000 +0100
+++ net-snmp-5.6.1/agent/snmpd.c	2011-01-25 18:45:19.000000000 +0100
@@ -425,7 +425,7 @@
     char            options[128] = "aAc:CdD::fhHI:l:L:m:M:n:p:P:qrsS:UvV-:Y:";
     int             arg, i, ret;
     int             dont_fork = 0, do_help = 0;
-    int             log_set = 0;
+    int             log_set = 0, use_stderr;
     int             uid = 0, gid = 0;
     int             agent_mode = -1;
     char           *cptr, **argvptr;
@@ -872,6 +872,12 @@
                                                    NETSNMP_DS_LIB_APPEND_LOGFILES));
 #endif
 
+    /* Check whether stderr was selected by user for logging before 
+     * initializing subagents which might unconditionally enable it
+     * just as a side effect.
+     */
+    use_stderr = snmp_stderrlog_status();
+
     /*
      * Initialize a argv set to the current for restarting the agent.   
      */
@@ -930,7 +936,7 @@
     if(!dont_fork) {
         int quit = ! netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID,
                                             NETSNMP_DS_AGENT_QUIT_IMMEDIATELY);
-        ret = netsnmp_daemonize(quit, snmp_stderrlog_status());
+        ret = netsnmp_daemonize(quit, use_stderr);
         /*
          * xxx-rks: do we care if fork fails? I think we should...
          */
------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to