On Mon, 21 Nov 2005 23:10:11 +0100 Thomas wrote:
TA> Robert Story wrote:
TA> > 1) [...] The only place this causes a problem is the startup message.
TA> [...]
TA> What about aligning with snmpd which currently does
TA>
TA> snmp_log(LOG_INFO, "NET-SNMP version %s\n", netsnmp_get_version());
TA>
TA> but perhaps adding "snmptrapd" for distinction?
works for me.
TA> > 2) message formatting [...]
TA> [...] but what's your actual proposal here?
a) eliminate different code paths for syslog vs logfile/print
b) eliminate the syslog or print handler, having one function for all logs.
c) eliminate the print[12] and syslog[12] tokens, using format[12] for both
A simple patch for (a) is attached.
TA> > Do we want to add an option to allow appending to log files? The option
TA> > used by snmpd, -A, does not appear to be used by snmptrapd.
TA>
TA> This'd be helpful, especially since 5.2.x and 5.3 have different default
TA> behaviour which cannot be changed now (IIUC).
No, the default could be changed by simply setting the new ds lib to the
non-default value before starting argument processing. Not that I'd recommend
that route.
--
Robert Story; NET-SNMP Junkie
Support: <http://www.net-snmp.org/> <irc://irc.freenode.net/#net-snmp>
Archive: <http://sourceforge.net/mailarchive/forum.php?forum=net-snmp-coders>
You are lost in a twisty maze of little standards, all different.
Index: apps/snmptrapd.c
===================================================================
RCS file: /cvsroot/net-snmp/net-snmp/apps/snmptrapd.c,v
retrieving revision 5.64
diff -u -p -r5.64 snmptrapd.c
--- apps/snmptrapd.c 15 Nov 2005 16:37:58 -0000 5.64
+++ apps/snmptrapd.c 21 Nov 2005 23:35:13 -0000
@@ -130,9 +130,6 @@ typedef long fd_mask;
#endif
char *logfile = 0;
-int Log = 0;
-int Print = 0;
-int Syslog = 0;
int SyslogTrap = 0;
int Event = 0;
int dropauth = 0;
@@ -526,9 +523,7 @@ parse_config_logOption(const char *token
int my_argc = 0 ;
char **my_argv = NULL;
- if (snmp_log_options( cptr, my_argc, my_argv ) >= 0 ) {
- Log++;
- }
+ snmp_log_options( cptr, my_argc, my_argv );
}
void
@@ -686,6 +681,11 @@ main(int argc, char *argv[])
dropauth = 1;
break;
+ case 'A':
+ netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID,
+ NETSNMP_DS_LIB_APPEND_LOGFILES, 1);
+ break;
+
case 'c':
if (optarg != NULL) {
netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID,
@@ -828,10 +828,11 @@ main(int argc, char *argv[])
case 'o':
fprintf(stderr,
"Warning: -o option is deprecated; use -Lf <file> instead\n");
- Print++;
if (optarg != NULL) {
logfile = optarg;
- snmp_enable_filelog(optarg, 0);
+ snmp_enable_filelog(optarg,
+ netsnmp_ds_get_boolean(NETSNMP_DS_LIBRARY_ID,
+ NETSNMP_DS_LIB_APPEND_LOGFILES));
} else {
usage();
exit(1);
@@ -853,7 +854,6 @@ main(int argc, char *argv[])
usage();
exit(1);
}
- Log++;
break;
case 'P':
@@ -861,14 +861,17 @@ main(int argc, char *argv[])
"Warning: -P option is deprecated; use -f -Le instead\n");
dofork = 0;
snmp_enable_stderrlog();
- Print++;
break;
case 's':
fprintf(stderr,
"Warning: -s option is deprecated; use -Lsd instead\n");
depmsg = 1;
- Syslog++;
+#ifdef WIN32
+ snmp_enable_syslog_ident(app_name_long, Facility);
+#else
+ snmp_enable_syslog_ident(app_name, Facility);
+#endif
break;
case 't':
@@ -943,8 +946,7 @@ main(int argc, char *argv[])
* return value from these registration calls.
* Don't try this at home, children!
*/
- if (!Log && !Print) {
- Syslog = 1;
+ if (0 == snmp_get_do_logging()) {
traph = netsnmp_add_global_traphandler(NETSNMPTRAPD_PRE_HANDLER,
syslog_handler);
traph->authtypes = TRAP_AUTH_LOG;
@@ -1125,29 +1127,21 @@ main(int argc, char *argv[])
}
#endif
- if (Syslog) {
-#ifdef WIN32
- snmp_enable_syslog_ident(app_name_long, Facility);
-#else
- snmp_enable_syslog_ident(app_name, Facility);
-#endif
- snmp_log(LOG_INFO, "Starting snmptrapd %s\n", netsnmp_get_version());
- if (depmsg) {
- snmp_log(LOG_WARNING, "-s and -S options are deprecated; use -Ls <facility> instead\n");
- }
- }
- if (Print || Log) {
+ if (1) {
struct tm *tm;
time_t timer;
time(&timer);
tm = localtime(&timer);
snmp_log(LOG_INFO,
- "%.4d-%.2d-%.2d %.2d:%.2d:%.2d NET-SNMP version %s Started.\n",
+ "%.4d-%.2d-%.2d %.2d:%.2d:%.2d NET-SNMP snmptrapd version %s Started.\n",
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
tm->tm_hour, tm->tm_min, tm->tm_sec,
netsnmp_get_version());
+ if (depmsg) {
+ snmp_log(LOG_WARNING, "-s and -S options are deprecated; use -Ls <facility> instead\n");
+ }
}
-
+
SOCK_STARTUP;
if (listen_ports)
@@ -1189,9 +1183,7 @@ main(int argc, char *argv[])
*/
snmptrapd_close_sessions(sess_list);
netsnmp_transport_free(transport);
- if (Syslog) {
- snmp_log(LOG_ERR, "couldn't open snmp - %m");
- }
+ snmp_log(LOG_ERR, "couldn't open snmp - %m");
SOCK_CLEANUP;
exit(1);
} else {
@@ -1222,7 +1214,7 @@ main(int argc, char *argv[])
#endif
while (netsnmp_running) {
if (reconfig) {
- if (Print || Log) {
+ if (snmp_get_do_logging()) {
struct tm *tm;
time_t timer;
time(&timer);
@@ -1242,8 +1234,7 @@ main(int argc, char *argv[])
tm->tm_hour, tm->tm_min, tm->tm_sec,
netsnmp_get_version());
}
- if (Syslog)
- snmp_log(LOG_INFO, "Snmptrapd reconfiguring");
+ snmp_log(LOG_INFO, "Snmptrapd reconfiguring");
trapd_update_config();
if (trap1_fmt_str_remember) {
free_trap1_fmt();
@@ -1291,7 +1282,7 @@ main(int argc, char *argv[])
run_alarms();
}
- if (Print || Log) {
+ if (snmp_get_do_logging()) {
struct tm *tm;
time_t timer;
time(&timer);
@@ -1301,10 +1292,8 @@ main(int argc, char *argv[])
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour,
tm->tm_min, tm->tm_sec, netsnmp_get_version());
}
- if (Syslog) {
- snmp_log(LOG_INFO, "Stopping snmptrapd");
- }
-
+ snmp_log(LOG_INFO, "Stopping snmptrapd");
+
snmptrapd_close_sessions(sess_list);
snmp_shutdown("snmptrapd");
#ifdef WIN32SERVICE