Allow debug log to be written to both syslog and file

If hostapd or wpa_supplicant is started with both -s and -f command line
arguments, debug log ended up being written only into syslog and the log
file was left empty. Change this so that the log entries will be written
to both places. Either -s or -f (or both) results in debug log to stdout
being disabled which was already the case.

Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2019-12-28 18:17:44 +02:00
parent 53a96146fb
commit 53661e3a9a
4 changed files with 77 additions and 78 deletions

View file

@ -768,7 +768,7 @@ int main(int argc, char *argv[])
if (log_file) if (log_file)
wpa_debug_open_file(log_file); wpa_debug_open_file(log_file);
else if (!log_file && !wpa_debug_syslog)
wpa_debug_setup_stdout(); wpa_debug_setup_stdout();
#ifdef CONFIG_DEBUG_SYSLOG #ifdef CONFIG_DEBUG_SYSLOG
if (wpa_debug_syslog) if (wpa_debug_syslog)

View file

@ -12,8 +12,6 @@
#ifdef CONFIG_DEBUG_SYSLOG #ifdef CONFIG_DEBUG_SYSLOG
#include <syslog.h> #include <syslog.h>
int wpa_debug_syslog = 0;
#endif /* CONFIG_DEBUG_SYSLOG */ #endif /* CONFIG_DEBUG_SYSLOG */
#ifdef CONFIG_DEBUG_LINUX_TRACING #ifdef CONFIG_DEBUG_LINUX_TRACING
@ -32,6 +30,10 @@ static FILE *wpa_debug_tracing_file = NULL;
int wpa_debug_level = MSG_INFO; int wpa_debug_level = MSG_INFO;
int wpa_debug_show_keys = 0; int wpa_debug_show_keys = 0;
int wpa_debug_timestamp = 0; int wpa_debug_timestamp = 0;
int wpa_debug_syslog = 0;
#ifndef CONFIG_NO_STDOUT_DEBUG
static FILE *out_file = NULL;
#endif /* CONFIG_NO_STDOUT_DEBUG */
#ifdef CONFIG_ANDROID_LOG #ifdef CONFIG_ANDROID_LOG
@ -61,8 +63,6 @@ static int wpa_to_android_level(int level)
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
static FILE *out_file = NULL;
#endif /* CONFIG_DEBUG_FILE */ #endif /* CONFIG_DEBUG_FILE */
@ -76,11 +76,11 @@ void wpa_debug_print_timestamp(void)
os_get_time(&tv); os_get_time(&tv);
#ifdef CONFIG_DEBUG_FILE #ifdef CONFIG_DEBUG_FILE
if (out_file) { if (out_file)
fprintf(out_file, "%ld.%06u: ", (long) tv.sec, fprintf(out_file, "%ld.%06u: ", (long) tv.sec,
(unsigned int) tv.usec); (unsigned int) tv.usec);
} else
#endif /* CONFIG_DEBUG_FILE */ #endif /* CONFIG_DEBUG_FILE */
if (!out_file && !wpa_debug_syslog)
printf("%ld.%06u: ", (long) tv.sec, (unsigned int) tv.usec); printf("%ld.%06u: ", (long) tv.sec, (unsigned int) tv.usec);
#endif /* CONFIG_ANDROID_LOG */ #endif /* CONFIG_ANDROID_LOG */
} }
@ -210,35 +210,37 @@ void wpa_printf(int level, const char *fmt, ...)
{ {
va_list ap; va_list ap;
va_start(ap, fmt);
if (level >= wpa_debug_level) { if (level >= wpa_debug_level) {
#ifdef CONFIG_ANDROID_LOG #ifdef CONFIG_ANDROID_LOG
va_start(ap, fmt);
__android_log_vprint(wpa_to_android_level(level), __android_log_vprint(wpa_to_android_level(level),
ANDROID_LOG_NAME, fmt, ap); ANDROID_LOG_NAME, fmt, ap);
va_end(ap);
#else /* CONFIG_ANDROID_LOG */ #else /* CONFIG_ANDROID_LOG */
#ifdef CONFIG_DEBUG_SYSLOG #ifdef CONFIG_DEBUG_SYSLOG
if (wpa_debug_syslog) { if (wpa_debug_syslog) {
va_start(ap, fmt);
vsyslog(syslog_priority(level), fmt, ap); vsyslog(syslog_priority(level), fmt, ap);
} else { va_end(ap);
}
#endif /* CONFIG_DEBUG_SYSLOG */ #endif /* CONFIG_DEBUG_SYSLOG */
wpa_debug_print_timestamp(); wpa_debug_print_timestamp();
#ifdef CONFIG_DEBUG_FILE #ifdef CONFIG_DEBUG_FILE
if (out_file) { if (out_file) {
va_start(ap, fmt);
vfprintf(out_file, fmt, ap); vfprintf(out_file, fmt, ap);
fprintf(out_file, "\n"); fprintf(out_file, "\n");
} else { va_end(ap);
}
#endif /* CONFIG_DEBUG_FILE */ #endif /* CONFIG_DEBUG_FILE */
if (!wpa_debug_syslog && !out_file) {
va_start(ap, fmt);
vprintf(fmt, ap); vprintf(fmt, ap);
printf("\n"); printf("\n");
#ifdef CONFIG_DEBUG_FILE va_end(ap);
} }
#endif /* CONFIG_DEBUG_FILE */
#ifdef CONFIG_DEBUG_SYSLOG
}
#endif /* CONFIG_DEBUG_SYSLOG */
#endif /* CONFIG_ANDROID_LOG */ #endif /* CONFIG_ANDROID_LOG */
} }
va_end(ap);
#ifdef CONFIG_DEBUG_LINUX_TRACING #ifdef CONFIG_DEBUG_LINUX_TRACING
if (wpa_debug_tracing_file != NULL) { if (wpa_debug_tracing_file != NULL) {
@ -254,7 +256,7 @@ void wpa_printf(int level, const char *fmt, ...)
static void _wpa_hexdump(int level, const char *title, const u8 *buf, static void _wpa_hexdump(int level, const char *title, const u8 *buf,
size_t len, int show) size_t len, int show, int only_syslog)
{ {
size_t i; size_t i;
@ -345,6 +347,7 @@ static void _wpa_hexdump(int level, const char *title, const u8 *buf,
syslog(syslog_priority(level), "%s - hexdump(len=%lu):%s", syslog(syslog_priority(level), "%s - hexdump(len=%lu):%s",
title, (unsigned long) len, display); title, (unsigned long) len, display);
bin_clear_free(strbuf, 1 + 3 * len); bin_clear_free(strbuf, 1 + 3 * len);
if (only_syslog)
return; return;
} }
#endif /* CONFIG_DEBUG_SYSLOG */ #endif /* CONFIG_DEBUG_SYSLOG */
@ -362,8 +365,9 @@ static void _wpa_hexdump(int level, const char *title, const u8 *buf,
fprintf(out_file, " [REMOVED]"); fprintf(out_file, " [REMOVED]");
} }
fprintf(out_file, "\n"); fprintf(out_file, "\n");
} else { }
#endif /* CONFIG_DEBUG_FILE */ #endif /* CONFIG_DEBUG_FILE */
if (!wpa_debug_syslog && !out_file) {
printf("%s - hexdump(len=%lu):", title, (unsigned long) len); printf("%s - hexdump(len=%lu):", title, (unsigned long) len);
if (buf == NULL) { if (buf == NULL) {
printf(" [NULL]"); printf(" [NULL]");
@ -374,21 +378,19 @@ static void _wpa_hexdump(int level, const char *title, const u8 *buf,
printf(" [REMOVED]"); printf(" [REMOVED]");
} }
printf("\n"); printf("\n");
#ifdef CONFIG_DEBUG_FILE
} }
#endif /* CONFIG_DEBUG_FILE */
#endif /* CONFIG_ANDROID_LOG */ #endif /* CONFIG_ANDROID_LOG */
} }
void wpa_hexdump(int level, const char *title, const void *buf, size_t len) void wpa_hexdump(int level, const char *title, const void *buf, size_t len)
{ {
_wpa_hexdump(level, title, buf, len, 1); _wpa_hexdump(level, title, buf, len, 1, 0);
} }
void wpa_hexdump_key(int level, const char *title, const void *buf, size_t len) void wpa_hexdump_key(int level, const char *title, const void *buf, size_t len)
{ {
_wpa_hexdump(level, title, buf, len, wpa_debug_show_keys); _wpa_hexdump(level, title, buf, len, wpa_debug_show_keys, 0);
} }
@ -421,13 +423,11 @@ static void _wpa_hexdump_ascii(int level, const char *title, const void *buf,
if (level < wpa_debug_level) if (level < wpa_debug_level)
return; return;
#ifdef CONFIG_ANDROID_LOG #ifdef CONFIG_ANDROID_LOG
_wpa_hexdump(level, title, buf, len, show); _wpa_hexdump(level, title, buf, len, show, 0);
#else /* CONFIG_ANDROID_LOG */ #else /* CONFIG_ANDROID_LOG */
#ifdef CONFIG_DEBUG_SYSLOG #ifdef CONFIG_DEBUG_SYSLOG
if (wpa_debug_syslog) { if (wpa_debug_syslog)
_wpa_hexdump(level, title, buf, len, show); _wpa_hexdump(level, title, buf, len, show, 1);
return;
}
#endif /* CONFIG_DEBUG_SYSLOG */ #endif /* CONFIG_DEBUG_SYSLOG */
wpa_debug_print_timestamp(); wpa_debug_print_timestamp();
#ifdef CONFIG_DEBUG_FILE #ifdef CONFIG_DEBUG_FILE
@ -436,13 +436,13 @@ static void _wpa_hexdump_ascii(int level, const char *title, const void *buf,
fprintf(out_file, fprintf(out_file,
"%s - hexdump_ascii(len=%lu): [REMOVED]\n", "%s - hexdump_ascii(len=%lu): [REMOVED]\n",
title, (unsigned long) len); title, (unsigned long) len);
return; goto file_done;
} }
if (buf == NULL) { if (buf == NULL) {
fprintf(out_file, fprintf(out_file,
"%s - hexdump_ascii(len=%lu): [NULL]\n", "%s - hexdump_ascii(len=%lu): [NULL]\n",
title, (unsigned long) len); title, (unsigned long) len);
return; goto file_done;
} }
fprintf(out_file, "%s - hexdump_ascii(len=%lu):\n", fprintf(out_file, "%s - hexdump_ascii(len=%lu):\n",
title, (unsigned long) len); title, (unsigned long) len);
@ -466,8 +466,10 @@ static void _wpa_hexdump_ascii(int level, const char *title, const void *buf,
pos += llen; pos += llen;
len -= llen; len -= llen;
} }
} else { }
file_done:
#endif /* CONFIG_DEBUG_FILE */ #endif /* CONFIG_DEBUG_FILE */
if (!wpa_debug_syslog && !out_file) {
if (!show) { if (!show) {
printf("%s - hexdump_ascii(len=%lu): [REMOVED]\n", printf("%s - hexdump_ascii(len=%lu): [REMOVED]\n",
title, (unsigned long) len); title, (unsigned long) len);
@ -478,7 +480,8 @@ static void _wpa_hexdump_ascii(int level, const char *title, const void *buf,
title, (unsigned long) len); title, (unsigned long) len);
return; return;
} }
printf("%s - hexdump_ascii(len=%lu):\n", title, (unsigned long) len); printf("%s - hexdump_ascii(len=%lu):\n", title,
(unsigned long) len);
while (len) { while (len) {
llen = len > line_len ? line_len : len; llen = len > line_len ? line_len : len;
printf(" "); printf(" ");
@ -499,9 +502,7 @@ static void _wpa_hexdump_ascii(int level, const char *title, const void *buf,
pos += llen; pos += llen;
len -= llen; len -= llen;
} }
#ifdef CONFIG_DEBUG_FILE
} }
#endif /* CONFIG_DEBUG_FILE */
#endif /* CONFIG_ANDROID_LOG */ #endif /* CONFIG_ANDROID_LOG */
} }

View file

@ -14,9 +14,7 @@
extern int wpa_debug_level; extern int wpa_debug_level;
extern int wpa_debug_show_keys; extern int wpa_debug_show_keys;
extern int wpa_debug_timestamp; extern int wpa_debug_timestamp;
#ifdef CONFIG_DEBUG_SYSLOG
extern int wpa_debug_syslog; extern int wpa_debug_syslog;
#endif /* CONFIG_DEBUG_SYSLOG */
/* Debugging function - conditional printf and hex dump. Driver wrappers can /* Debugging function - conditional printf and hex dump. Driver wrappers can
* use these for debugging purposes. */ * use these for debugging purposes. */

View file

@ -6701,7 +6701,7 @@ struct wpa_global * wpa_supplicant_init(struct wpa_params *params)
if (params->wpa_debug_file_path) if (params->wpa_debug_file_path)
wpa_debug_open_file(params->wpa_debug_file_path); wpa_debug_open_file(params->wpa_debug_file_path);
else if (!params->wpa_debug_file_path && !params->wpa_debug_syslog)
wpa_debug_setup_stdout(); wpa_debug_setup_stdout();
if (params->wpa_debug_syslog) if (params->wpa_debug_syslog)
wpa_debug_open_syslog(); wpa_debug_open_syslog();