void snmp_disable_log(void) { snmp_disable_syslog(); snmp_disable_filelog(); snmp_disable_stderrlog(); snmp_disable_calllog(); }
void snmp_enable_syslog(void) { snmp_disable_syslog(); #if HAVE_SYSLOG_H openlog("ucd-snmp", LOG_CONS|LOG_PID, LOG_DAEMON); do_syslogging=1; #endif }
RETSIGTYPE SnmpdCatchRandomSignal(int a) { /* Disable all logs and log the error via syslog */ snmp_disable_log(); snmp_enable_syslog(); snmp_log(LOG_ERR, "Exiting on signal %d\n", a); snmp_disable_syslog(); exit(1); }
void snmp_enable_syslog_ident(const char *ident, const int facility) { netsnmp_log_handler *logh; int found = 0; int enable = 1; #ifdef WIN32 HANDLE eventlog_h; #else void *eventlog_h = NULL; #endif snmp_disable_syslog(); /* only one syslog at a time */ #ifdef WIN32 eventlog_h = OpenEventLog(NULL, ident); if (eventlog_h == NULL) { /* * Hmmm..... * Maybe disable this handler, and log the error ? */ fprintf(stderr, "Could not open event log for %s. " "Last error: 0x%x\n", ident, GetLastError()); enable = 0; } #else openlog(snmp_log_syslogname(ident), LOG_CONS | LOG_PID, facility); #endif for (logh = logh_head; logh; logh = logh->next) if (logh->type == NETSNMP_LOGHANDLER_SYSLOG) { logh->magic = (void*)eventlog_h; logh->imagic = enable; /* syslog open */ if (logh->enabled && (0 == enable)) netsnmp_disable_this_loghandler(logh); else if ((0 == logh->enabled) && enable) netsnmp_enable_this_loghandler(logh); found = 1; } if (!found) { logh = netsnmp_register_loghandler(NETSNMP_LOGHANDLER_SYSLOG, LOG_DEBUG ); if (logh) { logh->magic = (void*)eventlog_h; logh->token = strdup(ident); logh->imagic = enable; /* syslog open */ if (logh->enabled && (0 == enable)) netsnmp_disable_this_loghandler(logh); else if ((0 == logh->enabled) && enable) netsnmp_enable_this_loghandler(logh); } } }
RETSIGTYPE SnmpdCatchRandomSignal(int a) { /* Disable all logs and log the error via syslog */ snmp_disable_log(); #ifndef NETSNMP_FEATURE_REMOVE_LOGGING_SYSLOG snmp_enable_syslog(); #endif /* NETSNMP_FEATURE_REMOVE_LOGGING_SYSLOG */ snmp_log(LOG_ERR, "Exiting on signal %d\n", a); #ifndef NETSNMP_FEATURE_REMOVE_LOGGING_SYSLOG snmp_disable_syslog(); #endif /* NETSNMP_FEATURE_REMOVE_LOGGING_SYSLOG */ exit(1); }