]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Allow debug log to be written to both syslog and file
authorJouni Malinen <j@w1.fi>
Sat, 28 Dec 2019 16:17:44 +0000 (18:17 +0200)
committerJouni Malinen <j@w1.fi>
Sat, 28 Dec 2019 16:28:10 +0000 (18:28 +0200)
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>
hostapd/main.c
src/utils/wpa_debug.c
src/utils/wpa_debug.h
wpa_supplicant/wpa_supplicant.c

index 8bfe24281ac59d5218a121f0697d823c6fd8eefc..e42069ba9aa877719b6b795787863017a5c4b57d 100644 (file)
@@ -768,7 +768,7 @@ int main(int argc, char *argv[])
 
        if (log_file)
                wpa_debug_open_file(log_file);
-       else
+       if (!log_file && !wpa_debug_syslog)
                wpa_debug_setup_stdout();
 #ifdef CONFIG_DEBUG_SYSLOG
        if (wpa_debug_syslog)
index c336e5389d0110fb804ea389527bf3e8d6f4e69d..a338a2039bb244d4a3d39862ee0372476c8f1e38 100644 (file)
@@ -12,8 +12,6 @@
 
 #ifdef CONFIG_DEBUG_SYSLOG
 #include <syslog.h>
-
-int wpa_debug_syslog = 0;
 #endif /* CONFIG_DEBUG_SYSLOG */
 
 #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_show_keys = 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
@@ -61,8 +63,6 @@ static int wpa_to_android_level(int level)
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-
-static FILE *out_file = NULL;
 #endif /* CONFIG_DEBUG_FILE */
 
 
@@ -76,12 +76,12 @@ void wpa_debug_print_timestamp(void)
 
        os_get_time(&tv);
 #ifdef CONFIG_DEBUG_FILE
-       if (out_file) {
+       if (out_file)
                fprintf(out_file, "%ld.%06u: ", (long) tv.sec,
                        (unsigned int) tv.usec);
-       } else
 #endif /* CONFIG_DEBUG_FILE */
-       printf("%ld.%06u: ", (long) tv.sec, (unsigned int) tv.usec);
+       if (!out_file && !wpa_debug_syslog)
+               printf("%ld.%06u: ", (long) tv.sec, (unsigned int) tv.usec);
 #endif /* CONFIG_ANDROID_LOG */
 }
 
@@ -210,35 +210,37 @@ void wpa_printf(int level, const char *fmt, ...)
 {
        va_list ap;
 
-       va_start(ap, fmt);
        if (level >= wpa_debug_level) {
 #ifdef CONFIG_ANDROID_LOG
+               va_start(ap, fmt);
                __android_log_vprint(wpa_to_android_level(level),
                                     ANDROID_LOG_NAME, fmt, ap);
+               va_end(ap);
 #else /* CONFIG_ANDROID_LOG */
 #ifdef CONFIG_DEBUG_SYSLOG
                if (wpa_debug_syslog) {
+                       va_start(ap, fmt);
                        vsyslog(syslog_priority(level), fmt, ap);
-               } else {
+                       va_end(ap);
+               }
 #endif /* CONFIG_DEBUG_SYSLOG */
                wpa_debug_print_timestamp();
 #ifdef CONFIG_DEBUG_FILE
                if (out_file) {
+                       va_start(ap, fmt);
                        vfprintf(out_file, fmt, ap);
                        fprintf(out_file, "\n");
-               } else {
-#endif /* CONFIG_DEBUG_FILE */
-               vprintf(fmt, ap);
-               printf("\n");
-#ifdef CONFIG_DEBUG_FILE
+                       va_end(ap);
                }
 #endif /* CONFIG_DEBUG_FILE */
-#ifdef CONFIG_DEBUG_SYSLOG
+               if (!wpa_debug_syslog && !out_file) {
+                       va_start(ap, fmt);
+                       vprintf(fmt, ap);
+                       printf("\n");
+                       va_end(ap);
                }
-#endif /* CONFIG_DEBUG_SYSLOG */
 #endif /* CONFIG_ANDROID_LOG */
        }
-       va_end(ap);
 
 #ifdef CONFIG_DEBUG_LINUX_TRACING
        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,
-                        size_t len, int show)
+                        size_t len, int show, int only_syslog)
 {
        size_t i;
 
@@ -345,7 +347,8 @@ static void _wpa_hexdump(int level, const char *title, const u8 *buf,
                syslog(syslog_priority(level), "%s - hexdump(len=%lu):%s",
                       title, (unsigned long) len, display);
                bin_clear_free(strbuf, 1 + 3 * len);
-               return;
+               if (only_syslog)
+                       return;
        }
 #endif /* CONFIG_DEBUG_SYSLOG */
        wpa_debug_print_timestamp();
@@ -362,33 +365,32 @@ static void _wpa_hexdump(int level, const char *title, const u8 *buf,
                        fprintf(out_file, " [REMOVED]");
                }
                fprintf(out_file, "\n");
-       } else {
-#endif /* CONFIG_DEBUG_FILE */
-       printf("%s - hexdump(len=%lu):", title, (unsigned long) len);
-       if (buf == NULL) {
-               printf(" [NULL]");
-       } else if (show) {
-               for (i = 0; i < len; i++)
-                       printf(" %02x", buf[i]);
-       } else {
-               printf(" [REMOVED]");
-       }
-       printf("\n");
-#ifdef CONFIG_DEBUG_FILE
        }
 #endif /* CONFIG_DEBUG_FILE */
+       if (!wpa_debug_syslog && !out_file) {
+               printf("%s - hexdump(len=%lu):", title, (unsigned long) len);
+               if (buf == NULL) {
+                       printf(" [NULL]");
+               } else if (show) {
+                       for (i = 0; i < len; i++)
+                               printf(" %02x", buf[i]);
+               } else {
+                       printf(" [REMOVED]");
+               }
+               printf("\n");
+       }
 #endif /* CONFIG_ANDROID_LOG */
 }
 
 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)
 {
-       _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)
                return;
 #ifdef CONFIG_ANDROID_LOG
-       _wpa_hexdump(level, title, buf, len, show);
+       _wpa_hexdump(level, title, buf, len, show, 0);
 #else /* CONFIG_ANDROID_LOG */
 #ifdef CONFIG_DEBUG_SYSLOG
-       if (wpa_debug_syslog) {
-               _wpa_hexdump(level, title, buf, len, show);
-               return;
-       }
+       if (wpa_debug_syslog)
+               _wpa_hexdump(level, title, buf, len, show, 1);
 #endif /* CONFIG_DEBUG_SYSLOG */
        wpa_debug_print_timestamp();
 #ifdef CONFIG_DEBUG_FILE
@@ -436,13 +436,13 @@ static void _wpa_hexdump_ascii(int level, const char *title, const void *buf,
                        fprintf(out_file,
                                "%s - hexdump_ascii(len=%lu): [REMOVED]\n",
                                title, (unsigned long) len);
-                       return;
+                       goto file_done;
                }
                if (buf == NULL) {
                        fprintf(out_file,
                                "%s - hexdump_ascii(len=%lu): [NULL]\n",
                                title, (unsigned long) len);
-                       return;
+                       goto file_done;
                }
                fprintf(out_file, "%s - hexdump_ascii(len=%lu):\n",
                        title, (unsigned long) len);
@@ -466,42 +466,43 @@ static void _wpa_hexdump_ascii(int level, const char *title, const void *buf,
                        pos += llen;
                        len -= llen;
                }
-       } else {
-#endif /* CONFIG_DEBUG_FILE */
-       if (!show) {
-               printf("%s - hexdump_ascii(len=%lu): [REMOVED]\n",
-                      title, (unsigned long) len);
-               return;
        }
-       if (buf == NULL) {
-               printf("%s - hexdump_ascii(len=%lu): [NULL]\n",
-                      title, (unsigned long) len);
-               return;
-       }
-       printf("%s - hexdump_ascii(len=%lu):\n", title, (unsigned long) len);
-       while (len) {
-               llen = len > line_len ? line_len : len;
-               printf("    ");
-               for (i = 0; i < llen; i++)
-                       printf(" %02x", pos[i]);
-               for (i = llen; i < line_len; i++)
+file_done:
+#endif /* CONFIG_DEBUG_FILE */
+       if (!wpa_debug_syslog && !out_file) {
+               if (!show) {
+                       printf("%s - hexdump_ascii(len=%lu): [REMOVED]\n",
+                              title, (unsigned long) len);
+                       return;
+               }
+               if (buf == NULL) {
+                       printf("%s - hexdump_ascii(len=%lu): [NULL]\n",
+                              title, (unsigned long) len);
+                       return;
+               }
+               printf("%s - hexdump_ascii(len=%lu):\n", title,
+                      (unsigned long) len);
+               while (len) {
+                       llen = len > line_len ? line_len : len;
+                       printf("    ");
+                       for (i = 0; i < llen; i++)
+                               printf(" %02x", pos[i]);
+                       for (i = llen; i < line_len; i++)
+                               printf("   ");
                        printf("   ");
-               printf("   ");
-               for (i = 0; i < llen; i++) {
-                       if (isprint(pos[i]))
-                               printf("%c", pos[i]);
-                       else
-                               printf("_");
+                       for (i = 0; i < llen; i++) {
+                               if (isprint(pos[i]))
+                                       printf("%c", pos[i]);
+                               else
+                                       printf("_");
+                       }
+                       for (i = llen; i < line_len; i++)
+                               printf(" ");
+                       printf("\n");
+                       pos += llen;
+                       len -= llen;
                }
-               for (i = llen; i < line_len; i++)
-                       printf(" ");
-               printf("\n");
-               pos += llen;
-               len -= llen;
-       }
-#ifdef CONFIG_DEBUG_FILE
        }
-#endif /* CONFIG_DEBUG_FILE */
 #endif /* CONFIG_ANDROID_LOG */
 }
 
index c94c4391fd63db36d7f5ff68a83ffe29f8743618..c6d5cc647f75d5ddcef87e854fc9fd75590d86b5 100644 (file)
@@ -14,9 +14,7 @@
 extern int wpa_debug_level;
 extern int wpa_debug_show_keys;
 extern int wpa_debug_timestamp;
-#ifdef CONFIG_DEBUG_SYSLOG
 extern int wpa_debug_syslog;
-#endif /* CONFIG_DEBUG_SYSLOG */
 
 /* Debugging function - conditional printf and hex dump. Driver wrappers can
  * use these for debugging purposes. */
index 195ff74b0e3a356c846d3d6938b3c9b5430abba2..2ef1dcdc12537804530d001f60b44a3c7e22b5ad 100644 (file)
@@ -6701,7 +6701,7 @@ struct wpa_global * wpa_supplicant_init(struct wpa_params *params)
 
        if (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();
        if (params->wpa_debug_syslog)
                wpa_debug_open_syslog();