aboutsummaryrefslogtreecommitdiffstats
path: root/dumpcap.c
diff options
context:
space:
mode:
authorJoão Valverde <j@v6e.pt>2021-06-24 21:20:25 +0100
committerJoão Valverde <j@v6e.pt>2021-06-26 00:18:26 +0100
commitc6a920686ce59ea8b29f7a61f8197077baedf304 (patch)
treeda6268c7e6fce9e38f99190f08fe3c08b5301b38 /dumpcap.c
parentc2c256f0d8afa76599d7c3f3dcfac23c02069209 (diff)
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.
Diffstat (limited to 'dumpcap.c')
-rw-r--r--dumpcap.c78
1 files changed, 39 insertions, 39 deletions
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<argc; i++) {
+ if (strcmp("-Z", argv[i]) == 0) {
+ capture_child = TRUE;
+ machine_readable = TRUE; /* request machine-readable output */
+#ifdef _WIN32
+ /* set output pipe to binary mode, to avoid ugly text conversions */
+ _setmode(2, O_BINARY);
+#endif
+ }
+ }
cmdarg_err_init(dumpcap_cmdarg_err, dumpcap_cmdarg_err_cont);
+ /* Initialize log handler early so we can have proper logging during startup. */
+ ws_log_init_with_writer("dumpcap", dumpcap_log_writer, vcmdarg_err);
+
/* Early logging command-line initialization. */
ws_log_parse_args(&argc, argv, vcmdarg_err, 1);
@@ -4924,43 +4961,6 @@ main(int argc, char *argv[])
}
#endif
- /*
- * 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<argc; i++) {
- if (strcmp("-Z", argv[i]) == 0) {
- capture_child = TRUE;
- machine_readable = TRUE; /* request machine-readable output */
-#ifdef _WIN32
- /* set output pipe to binary mode, to avoid ugly text conversions */
- _setmode(2, O_BINARY);
-#endif
- }
- }
-
/* Initialize the pcaps list and IDBs */
global_ld.pcaps = g_array_new(FALSE, FALSE, sizeof(capture_src *));
global_ld.pcapng_passthrough = FALSE;