aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Thacker <johnthacker@gmail.com>2023-03-08 09:25:51 -0500
committerJohn Thacker <johnthacker@gmail.com>2023-03-08 21:22:51 -0500
commit2a7e4982a55b0d8e1a22f42cf6bb1e410daa92c0 (patch)
tree301557e49c2b85c7a9c905b58701ff85b5530016
parent92fb89524100a3b71636080e24a7a3aca8a7b2c9 (diff)
dumpcap: Make debugging compile again
Commit e921b804d0174b2bb5a118df8b454c0dc2e69369 removed the user data parameter from logging, so remove it here. Explain how the debugging defines work. If DEBUG_DUMPCAP is defined and dumpcap is a capture child, don't send logs to stderr with normal formatting, because that will be connected to the sync pipe. Don't send them to stdout either, because that can be connected to a data pipe (e.g., for retrieving interface information.) Instead, send it to stderr with the special formatting so that the parent recognizes it. Use va_copy if both DEBUG_DUMPCAP and DEBUG_CHILD_DUMPCAP are defined, avoiding undefined behavior that can lead to segfaults. Set the log level to DEBUG when running as a capture child if the DEBUG defines are set, because sync_pipe_start doesn't pass along log level information. If you turned on the extra #define, you presumably want to debug. If logging to a file, open the file before any log messages. Get rid of a check for the log level being below the default level. It's either redundant of a check already done in ws_log_full, or it prevents logs from being shown when dumpcap is run standalone with logging options.
-rw-r--r--dumpcap.c60
1 files changed, 42 insertions, 18 deletions
diff --git a/dumpcap.c b/dumpcap.c
index ce3303bbb8..0fc0d25f37 100644
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -93,8 +93,13 @@
#include "wiretap/pcapng_module.h"
#include "wiretap/pcapng.h"
-/**#define DEBUG_DUMPCAP**/
-/**#define DEBUG_CHILD_DUMPCAP**/
+/*
+ * Define these for extra logging messages at INFO and below. Note
+ * that when dumpcap is spawned as a child process, logs are sent
+ * to the parent via the sync pipe.
+ */
+/**#define DEBUG_DUMPCAP**/ /* Logs INFO and below messages normally */
+/**#define DEBUG_CHILD_DUMPCAP**/ /* Writes INFO and below logs to file */
#ifdef _WIN32
#include "wsutil/win32-utils.h"
@@ -107,6 +112,9 @@
FILE *debug_log; /* for logging debug messages to */
/* a file if DEBUG_CHILD_DUMPCAP */
/* is defined */
+#ifdef DEBUG_DUMPCAP
+#include <stdarg.h> /* va_copy */
+#endif
#endif
static GAsyncQueue *pcap_queue;
@@ -4910,6 +4918,23 @@ main(int argc, char *argv[])
/* Early logging command-line initialization. */
ws_log_parse_args(&argc, argv, vcmdarg_err, 1);
+#if defined(DEBUG_DUMPCAP) || defined(DEBUG_CHILD_DUMPCAP)
+ /* sync_pipe_start does not pass along log level information from
+ * the parent (XXX: it probably should.) Assume that if we're
+ * specially compiled with dumpcap debugging then we want it on.
+ */
+ if (capture_child) {
+ ws_log_set_level(LOG_LEVEL_DEBUG);
+ }
+#endif
+
+#ifdef DEBUG_CHILD_DUMPCAP
+ if ((debug_log = ws_fopen("dumpcap_debug_log.tmp","w")) == NULL) {
+ fprintf (stderr, "Unable to open debug log file .\n");
+ exit (1);
+ }
+#endif
+
ws_noisy("Finished log init and parsing command line log arguments");
#ifdef _WIN32
@@ -4945,13 +4970,6 @@ main(int argc, char *argv[])
#define OPTSTRING OPTSTRING_CAPTURE_COMMON "C:dghk:" OPTSTRING_m "MN:nPq" OPTSTRING_r "St" OPTSTRING_u "vw:Z:"
-#ifdef DEBUG_CHILD_DUMPCAP
- if ((debug_log = ws_fopen("dumpcap_debug_log.tmp","w")) == NULL) {
- fprintf (stderr, "Unable to open debug log file .\n");
- exit (1);
- }
-#endif
-
#if defined(__APPLE__) && defined(__LP64__)
/*
* Is this Mac OS X 10.6.0, 10.6.1, 10.6.3, or 10.6.4? If so, we need
@@ -5597,21 +5615,27 @@ dumpcap_log_writer(const char *domain, enum ws_log_level level,
const char *user_format, va_list user_ap,
void *user_data _U_)
{
- /* ignore log message, if log_level isn't interesting */
- if (level <= LOG_LEVEL_INFO) {
-#if !defined(DEBUG_DUMPCAP) && !defined(DEBUG_CHILD_DUMPCAP)
- return;
-#endif
- }
-
/* DEBUG & INFO msgs (if we're debugging today) */
#if defined(DEBUG_DUMPCAP) || defined(DEBUG_CHILD_DUMPCAP)
if (level <= LOG_LEVEL_INFO && ws_log_msg_is_active(domain, level)) {
#ifdef DEBUG_DUMPCAP
- ws_log_console_writer(domain, level, timestamp, file, line, func, user_format, user_ap, NULL);
+#ifdef DEBUG_CHILD_DUMPCAP
+ va_list user_ap_copy;
+ va_copy(user_ap_copy, user_ap);
#endif
+ if (capture_child) {
+ gchar *msg = ws_strdup_vprintf(user_format, user_ap);
+ sync_pipe_errmsg_to_parent(2, msg, "");
+ g_free(msg);
+ } else {
+ ws_log_console_writer(domain, level, timestamp, file, line, func, user_format, user_ap);
+ }
#ifdef DEBUG_CHILD_DUMPCAP
- ws_log_file_writer(debug_log, domain, level, timestamp, file, line, func, user_format, user_ap, NULL);
+ ws_log_file_writer(debug_log, domain, level, timestamp, file, line, func, user_format, user_ap_copy);
+ va_end(user_ap_copy);
+#endif
+#elif DEBUG_CHILD_DUMPCAP
+ ws_log_file_writer(debug_log, domain, level, timestamp, file, line, func, user_format, user_ap);
#endif
return;
}