X-Git-Url: https://git.tcpdump.org/libpcap/blobdiff_plain/db1104b9632642bfadfa4e2e2b772ac1265fb280..09b51d326c38ea8e10ce4da09c09d50e08c5aeb8:/rpcapd/log.c diff --git a/rpcapd/log.c b/rpcapd/log.c index 414e9542..f26c145e 100644 --- a/rpcapd/log.c +++ b/rpcapd/log.c @@ -1,3 +1,28 @@ +/* + * Copyright (c) 1993, 1994, 1995, 1996, 1998 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that: (1) source code distributions + * retain the above copyright notice and this paragraph in its entirety, (2) + * distributions including binary code include the above copyright notice and + * this paragraph in its entirety in the documentation or other materials + * provided with the distribution, and (3) all advertising materials mentioning + * features or use of this software display the following acknowledgement: + * ``This product includes software developed by the University of California, + * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of + * the University nor the names of its contributors may be used to endorse + * or promote products derived from this software without specific prior + * written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include #include @@ -8,6 +33,8 @@ #include #endif +#include "portability.h" + #include "log.h" static int log_to_systemlog; @@ -61,17 +88,22 @@ static void rpcapd_vlog_systemlog(log_priority, PCAP_FORMAT_STRING(const char *), va_list) PCAP_PRINTFLIKE(2, 0); #ifdef _WIN32 -static HANDLE log_handle = INVALID_HANDLE; - #define MESSAGE_SUBKEY \ "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\rpcapd" -static void rpcapd_log_init(void) +static void rpcapd_vlog_systemlog(log_priority priority, const char *message, + va_list ap) { - if (log_to_systemlog) - { - HKEY hey_handle; +#if 0 + static int initialized = 0; + HKEY hey_handle; + static HANDLE log_handle; + WORD eventlog_type; + DWORD event_id; + char msgbuf[1024]; + char *strings[1]; + if (!initialized) { /* * Register our message stuff in the Registry. * @@ -82,27 +114,17 @@ static void rpcapd_log_init(void) if (RegCreateKey(HKEY_LOCAL_MACHINE, MESSAGE_SUBKEY, &key_handle) != ERROR_SUCCESS) { /* - * Failed - give up and just log to the + * Failed - give up and just log this message, + * and all subsequent messages, to the * standard error. */ log_to_systemlog = 0; + initialized = 1; + rpcapd_vlog_stderr(priority, message, ap); return; } log_handle = RegisterEventSource(NULL, "rpcapd"); - } -} - -static void rpcapd_vlog_systemlog(log_priority priority, const char *message, - va_list ap) -{ - WORD eventlog_type; - DWORD event_id; - char msgbuf[1024]; - char *strings[1]; - - if (log_handle == INVALID_HANDLE) { - /* Failed to initialize, or haven't tried */ - return; + initialized = 1; } switch (priority) { @@ -143,21 +165,25 @@ static void rpcapd_vlog_systemlog(log_priority priority, const char *message, */ (void) ReportEvent(log_handle, eventlog_type, 0, event_id, NULL, 1, 0, strings, NULL); -} #else -static void rpcapd_log_init(void) -{ - if (log_to_systemlog) - { - openlog("rpcapd", LOG_PID, LOG_DAEMON); - } + rpcapd_vlog_stderr(priority, message, ap); +#endif } - +#else static void rpcapd_vlog_systemlog(log_priority priority, const char *message, va_list ap) { + static int initialized = 0; int syslog_priority; + if (!initialized) { + // + // Open the log. + // + openlog("rpcapd", LOG_PID, LOG_DAEMON); + initialized = 1; + } + switch (priority) { case LOGPRIO_DEBUG: @@ -181,7 +207,31 @@ static void rpcapd_vlog_systemlog(log_priority priority, const char *message, return; } +#ifdef HAVE_VSYSLOG vsyslog(syslog_priority, message, ap); +#else + /* + * Thanks, IBM, for not providing vsyslog() in AIX! + * + * They also warn that the syslog functions shouldn't + * be used in multithreaded programs, but the only thing + * obvious that seems to make the syslog_r functions + * better is that they have an additional argument + * that points to the information that's static to + * the syslog code in non-thread-safe versions. Most + * of that data is set by openlog(); since we already + * do an openlog before doing logging, and don't + * change that data afterwards, I suspect that, in + * practice, the regular syslog routines are OK for + * us (especially given that we'd end up having one + * static struct syslog_data anyway, which means we'd + * just be like the non-thread-safe version). + */ + char logbuf[1024+1]; + + vsnprintf(logbuf, sizeof logbuf, message, ap); + syslog(syslog_priority, "%s", logbuf); +#endif } #endif @@ -193,17 +243,8 @@ void rpcapd_log_set(int log_to_systemlog_arg, int log_debug_messages_arg) void rpcapd_log(log_priority priority, const char *message, ...) { - static int initialized = 0; va_list ap; - if (!initialized) { - // - // Initialize the logging system. - // - rpcapd_log_init(); - initialized = 1; - } - if (priority != LOGPRIO_DEBUG || log_debug_messages) { va_start(ap, message); if (log_to_systemlog)