From c6a920686ce59ea8b29f7a61f8197077baedf304 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Valverde?= Date: Thu, 24 Jun 2021 21:20:25 +0100 Subject: [PATCH] wslog: Check environment initialization for errors Initialiaze the cmdarg error stream earlier. Dumpcap also needs to know earlier if it is running in capture child mode. --- capinfos.c | 5 +- captype.c | 6 +- debian/libwsutil0.symbols | 3 +- dftest.c | 6 +- dumpcap.c | 78 ++++++++++++------------- editcap.c | 6 +- extcap/androiddump.c | 6 +- extcap/ciscodump.c | 5 +- extcap/dpauxmon.c | 3 + extcap/etwdump.c | 3 + extcap/randpktdump.c | 6 +- extcap/sdjournal.c | 3 + extcap/sshdump.c | 3 + extcap/udpdump.c | 3 + fuzz/fuzzshark.c | 9 ++- mergecap.c | 6 +- randpkt.c | 6 +- rawshark.c | 6 +- reordercap.c | 6 +- sharkd.c | 6 +- text2pcap.c | 12 +++- tfshark.c | 14 ++--- tshark.c | 6 +- ui/qt/main.cpp | 5 +- wsutil/wslog.c | 119 +++++++++++++++++++++++++------------- wsutil/wslog.h | 23 ++++++-- 26 files changed, 217 insertions(+), 137 deletions(-) diff --git a/capinfos.c b/capinfos.c index 015e0c1e64..9043c25a0f 100644 --- a/capinfos.c +++ b/capinfos.c @@ -1581,11 +1581,10 @@ main(int argc, char *argv[]) setlocale(LC_ALL, ""); #endif + cmdarg_err_init(capinfos_cmdarg_err, capinfos_cmdarg_err_cont); /* Initialize log handler early so we can have proper logging during startup. */ - ws_log_init("capinfos", NULL); - - cmdarg_err_init(capinfos_cmdarg_err, capinfos_cmdarg_err_cont); + ws_log_init("capinfos", vcmdarg_err); /* Early logging command-line initialization. */ ws_log_parse_args(&argc, argv, vcmdarg_err, INVALID_OPTION); diff --git a/captype.c b/captype.c index 96edb84443..558aa9465b 100644 --- a/captype.c +++ b/captype.c @@ -120,11 +120,11 @@ main(int argc, char *argv[]) setlocale(LC_ALL, ""); #endif - /* Initialize log handler early so we can have proper logging during startup. */ - ws_log_init("captype", NULL); - cmdarg_err_init(captype_cmdarg_err, captype_cmdarg_err_cont); + /* Initialize log handler early so we can have proper logging during startup. */ + ws_log_init("captype", vcmdarg_err); + /* Early logging command-line initialization. */ ws_log_parse_args(&argc, argv, vcmdarg_err, 1); diff --git a/debian/libwsutil0.symbols b/debian/libwsutil0.symbols index 9b6d842b4d..5885cf0d90 100644 --- a/debian/libwsutil0.symbols +++ b/debian/libwsutil0.symbols @@ -235,7 +235,8 @@ libwsutil.so.0 libwsutil0 #MINVER# ws_log_full@Base 3.5.0 ws_log_get_level@Base 3.5.0 ws_log_init@Base 3.5.0 - ws_log_init_with_data@Base 3.5.0 + ws_log_init_with_writer@Base 3.5.0 + ws_log_init_with_writer_and_data@Base 3.5.0 ws_log_level_to_string@Base 3.5.0 ws_log_msg_is_active@Base 3.5.0 ws_log_parse_args@Base 3.5.0 diff --git a/dftest.c b/dftest.c index 4d497f52e6..1c0a4db6b0 100644 --- a/dftest.c +++ b/dftest.c @@ -60,11 +60,11 @@ main(int argc, char **argv) dfilter_t *df; gchar *err_msg; - /* Initialize log handler early so we can have proper logging during startup. */ - ws_log_init("dftest", NULL); - cmdarg_err_init(dftest_cmdarg_err, dftest_cmdarg_err_cont); + /* Initialize log handler early so we can have proper logging during startup. */ + ws_log_init("dftest", vcmdarg_err); + /* Early logging command-line initialization. */ ws_log_parse_args(&argc, argv, vcmdarg_err, 1); diff --git a/dumpcap.c b/dumpcap.c index 06e1f138ee..a88103b0a8 100644 --- a/dumpcap.c +++ b/dumpcap.c @@ -4854,11 +4854,48 @@ main(int argc, char *argv[]) #endif GString *str; - /* Initialize log handler early so we can have proper logging during startup. */ - ws_log_init("dumpcap", dumpcap_log_writer); + /* + * Determine if dumpcap is being requested to run in a special + * capture_child mode by going thru the command line args to see if + * a -Z is present. (-Z is a hidden option). + * + * The primary result of running in capture_child mode is that + * all messages sent out on stderr are in a special type/len/string + * format to allow message processing by type. These messages include + * error messages if dumpcap fails to start the operation it was + * requested to do, as well as various "status" messages which are sent + * when an actual capture is in progress, and a "success" message sent + * if dumpcap was requested to perform an operation other than a + * capture. + * + * Capture_child mode would normally be requested by a parent process + * which invokes dumpcap and obtains dumpcap stderr output via a pipe + * to which dumpcap stderr has been redirected. It might also have + * another pipe to obtain dumpcap stdout output; for operations other + * than a capture, that information is formatted specially for easier + * parsing by the parent process. + * + * Capture_child mode needs to be determined immediately upon + * startup so that any messages generated by dumpcap in this mode + * (eg: during initialization) will be formatted properly. + */ + + for (i=1; i