I'd like to see what folks think of changing the behavior of logging when no
log destination is enabled.
The stderr log is enabled if a message is logged before any log handlers are
enabled:
$ snmptranslate -Dget_mib_directory .1
No log handling enabled - turning on stderr logging
registered debug token get_mib_directory, 1
get_mib_directory: no mib directories set
get_mib_directory: no mib directories set by environment
get_mib_directory: mib directories set by config
get_mib_directory: mib directories set
'/usr/share/snmp/mibs:/home/rks/.snmp/ietf-updates:/home/rks/.snmp/mibs'
get_mib_directory: mib directories set
'/usr/share/snmp/mibs:/home/rks/.snmp/ietf-updates:/home/rks/.snmp/mibs'
iso
The problem is, it is not disabled if a log handler is added. This results in
multiple lines being logged, stepping over each other:
$ snmptranslate -Dget_mib_directory -Lo .1
No log handling enabled - turning on stderr logging
registered debug token get_mib_directory, 1
get_mib_directory: get_mib_directory: no mib directories set
no mib directories set
get_mib_directory: get_mib_directory: no mib directories set by environment
no mib directories set by environment
get_mib_directory: get_mib_directory: mib directories set by config
mib directories set by config
get_mib_directory: get_mib_directory: mib directories set
'/usr/share/snmp/mibs:/home/rks/.snmp/ietf-updates:/home/rks/.snmp/mibs'
mib directories set
'/usr/share/snmp/mibs:/home/rks/.snmp/ietf-updates:/home/rks/.snmp/mibs'
get_mib_directory: get_mib_directory: mib directories set
'/usr/share/snmp/mibs:/home/rks/.snmp/ietf-updates:/home/rks/.snmp/mibs'
mib directories set
'/usr/share/snmp/mibs:/home/rks/.snmp/ietf-updates:/home/rks/.snmp/mibs'
iso
I've attached a patch to fix this. It simply calls the stderr log hander
directly instead of registering a handler. it keeps the warning, and adds
another when switching away from stderr logging. Personally, I'd rather both
these warnings go away. netsnmp_parse_args is enabling stderr logging by
default, just to get rid of this message. My patch also removes this call, and
other places where it's begin called just to avoid the warning. If people hate
the warning, lets remove it, not go around enabling log handlers willy nilly.
Robert
diff --git a/net-snmp/apps/snmptranslate.c b/net-snmp/apps/snmptranslate.c
index cbe647c..2375f9d 100644
--- a/net-snmp/apps/snmptranslate.c
+++ b/net-snmp/apps/snmptranslate.c
@@ -235,7 +235,6 @@ main(int argc, char *argv[])
}
}
- snmp_enable_stderrlog();
init_snmp("snmpapp");
if (optind < argc)
current_name = argv[optind];
diff --git a/net-snmp/snmplib/cert_util.c b/net-snmp/snmplib/cert_util.c
index 3818b20..c98038d 100644
--- a/net-snmp/snmplib/cert_util.c
+++ b/net-snmp/snmplib/cert_util.c
@@ -767,7 +767,6 @@ main(int argc, char** argv)
default:
fprintf(stderr,"unknown option %c\n", ch);
}
- snmp_enable_stderrlog();
init_snmp("main-full");
diff --git a/net-snmp/snmplib/snmp_logging.c b/net-snmp/snmplib/snmp_logging.c
index a81cda6..cf06012 100644
--- a/net-snmp/snmplib/snmp_logging.c
+++ b/net-snmp/snmplib/snmp_logging.c
@@ -1150,6 +1168,11 @@ log_handler_null( netsnmp_log_handler* logh, int pri, const char *str)
void
snmp_log_string(int priority, const char *str)
{
+ static netsnmp_log_handler *old_head = NULL;
+ static int stderr_enabled = 0;
+ static netsnmp_log_handler lh = { 1, 0, 0, 0, "stderr",
+ log_handler_stdouterr, 0, NULL, NULL,
+ NULL };
netsnmp_log_handler *logh;
/*
@@ -1157,10 +1180,22 @@ snmp_log_string(int priority, const char *str)
* If you don't want stderr logging, then enable something else.
*/
if (!logh_head) {
- snmp_enable_stderrlog();
- snmp_log_string(LOG_WARNING,
- "No log handling enabled - turning on stderr logging\n");
+ if (!stderr_enabled) {
+ ++stderr_enabled;
+ netsnmp_set_line_buffering(stderr);
+ log_handler_stdouterr( &lh, LOG_WARNING,
+ "No log handling enabled - using stderr logging\n");
+ }
+ log_handler_stdouterr( &lh, priority, str );
+
+ return;
+ }
+ else if (!old_head && stderr_enabled) {
+ old_head = logh_head;
+ log_handler_stdouterr( &lh, LOG_WARNING,
+ "Log handling defined - disabling stderr\n" );
}
+
/*
* Start at the given priority, and work "upwards"....
diff --git a/net-snmp/snmplib/snmp_parse_args.c b/net-snmp/snmplib/snmp_parse_args.c
index 8c7a860..da8fa76 100644
--- a/net-snmp/snmplib/snmp_parse_args.c
+++ b/net-snmp/snmplib/snmp_parse_args.c
@@ -200,7 +200,6 @@ netsnmp_parse_args(int argc,
char *Xpsz = NULL;
char *Cpsz = NULL;
char Opts[BUF_SIZE];
- int logopt = flags & NETSNMP_PARSE_ARGS_NOLOGGING;
int zero_sensitive = !( flags & NETSNMP_PARSE_ARGS_NOZERO );
/*
@@ -380,7 +379,6 @@ netsnmp_parse_args(int argc,
if (snmp_log_options(optarg, argc, argv) < 0) {
return (-1);
}
- logopt = 1;
break;
#define SNMPV3_CMD_OPTIONS
@@ -595,9 +593,6 @@ netsnmp_parse_args(int argc,
}
DEBUGMSGTL(("snmp_parse_args", "finished: %d/%d\n", optind, argc));
- if (!logopt)
- snmp_enable_stderrlog();
-
/*
* read in MIB database and initialize the snmp library
*/
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders