Skip to content

Commit

Permalink
wslog: Check if we are initialized and add missing inits
Browse files Browse the repository at this point in the history
Instead of receiving the program name from GLib, pass it explicitly
to ws_log_init() instead  and use that to initialize the GLib program
name.

ws_log_parse_args() will now exit the program when it encounters an
argument error if exit_failure >= 0.
  • Loading branch information
randstr authored and Wireshark GitLab Utility committed Jun 21, 2021
1 parent c216bb8 commit 759bb23
Show file tree
Hide file tree
Showing 24 changed files with 161 additions and 70 deletions.
8 changes: 8 additions & 0 deletions capinfos.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
#include <wsutil/str_util.h>
#include <wsutil/file_util.h>
#include <wsutil/ws_assert.h>
#include <wsutil/wslog.h>

#include <wsutil/wsgcrypt.h>

Expand Down Expand Up @@ -1580,8 +1581,15 @@ main(int argc, char *argv[])
setlocale(LC_ALL, "");
#endif


/* 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);

/* Early logging command-line initialization. */
ws_log_parse_args(&argc, argv, vcmdarg_err, INVALID_OPTION);

/* Get the decimal point. */
decimal_point = g_strdup(localeconv()->decimal_point);

Expand Down
7 changes: 7 additions & 0 deletions captype.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

#include <wsutil/report_message.h>
#include <wsutil/str_util.h>
#include <wsutil/wslog.h>

#include "ui/failure_message.h"

Expand Down Expand Up @@ -119,8 +120,14 @@ 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);

/* Early logging command-line initialization. */
ws_log_parse_args(&argc, argv, vcmdarg_err, 1);

/* Initialize the version information. */
ws_init_version_info("Captype (Wireshark)", NULL, NULL, NULL);

Expand Down
7 changes: 7 additions & 0 deletions dftest.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <wsutil/filesystem.h>
#include <wsutil/privileges.h>
#include <wsutil/report_message.h>
#include <wsutil/wslog.h>

#include <wiretap/wtap.h>

Expand Down Expand Up @@ -59,8 +60,14 @@ 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);

/* Early logging command-line initialization. */
ws_log_parse_args(&argc, argv, vcmdarg_err, 1);

/*
* Get credential information for later use.
*/
Expand Down
10 changes: 3 additions & 7 deletions dumpcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -4851,17 +4851,13 @@ main(int argc, char *argv[])
#endif
GString *str;

g_set_prgname("dumpcap");

/* Initialize log handler early so we can have proper logging during startup. */
ws_log_init(dumpcap_log_writer);
ws_log_init("dumpcap", dumpcap_log_writer);

cmdarg_err_init(dumpcap_cmdarg_err, dumpcap_cmdarg_err_cont);

/* Command line options are parsed too late to configure logging, do it
manually. */
if (ws_log_parse_args(&argc, argv, cmdarg_err) != 0)
exit(1);
/* Early logging command-line initialization. */
ws_log_parse_args(&argc, argv, vcmdarg_err, 1);

#ifdef _WIN32
create_app_running_mutex();
Expand Down
7 changes: 7 additions & 0 deletions editcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
#include <wsutil/pint.h>
#include <wsutil/strtoi.h>
#include <wsutil/ws_assert.h>
#include <wsutil/wslog.h>
#include <wiretap/wtap_opttypes.h>

#include "ui/failure_message.h"
Expand Down Expand Up @@ -1153,8 +1154,14 @@ main(int argc, char *argv[])
gboolean valid_seed = FALSE;
unsigned int seed = 0;

/* Initialize log handler early so we can have proper logging during startup. */
ws_log_init("editcap", NULL);

cmdarg_err_init(editcap_cmdarg_err, editcap_cmdarg_err_cont);

/* Early logging command-line initialization. */
ws_log_parse_args(&argc, argv, vcmdarg_err, INVALID_OPTION);

#ifdef _WIN32
create_app_running_mutex();
#endif /* _WIN32 */
Expand Down
10 changes: 3 additions & 7 deletions extcap/androiddump.c
Original file line number Diff line number Diff line change
Expand Up @@ -2528,17 +2528,13 @@ int main(int argc, char *argv[]) {
char *help_url;
char *help_header = NULL;

g_set_prgname("androiddump");

/* Initialize log handler early so we can have proper logging during startup. */
ws_log_init(NULL);
ws_log_init("androiddump", NULL);

cmdarg_err_init(androiddump_cmdarg_err, androiddump_cmdarg_err);

/* Command line options are parsed too late to configure logging, do it
manually. */
if (ws_log_parse_args(&argc, argv, cmdarg_err) != 0)
return EXIT_FAILURE;
/* Early logging command-line initialization. */
ws_log_parse_args(&argc, argv, vcmdarg_err, EXIT_FAILURE);

/*
* Get credential information for later use.
Expand Down
3 changes: 3 additions & 0 deletions extcap/ciscodump.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,9 @@ int main(int argc, char *argv[])
char* help_url;
char* help_header = NULL;

/* Initialize log handler early so we can have proper logging during startup. */
ws_log_init("ciscodump", NULL);

/*
* Get credential information for later use.
*/
Expand Down
3 changes: 3 additions & 0 deletions extcap/dpauxmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,9 @@ int main(int argc, char *argv[])
extcap_parameters* extcap_conf = g_new0(extcap_parameters, 1);
char* help_header = NULL;

/* Initialize log handler early so we can have proper logging during startup. */
ws_log_init("dpauxmon", NULL);

/*
* Get credential information for later use.
*/
Expand Down
3 changes: 3 additions & 0 deletions extcap/etwdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ int main(int argc, char* argv[])
char* help_url;
char* help_header = NULL;

/* Initialize log handler early so we can have proper logging during startup. */
ws_log_init("etwdump", NULL);

/*
* Get credential information for later use.
*/
Expand Down
10 changes: 3 additions & 7 deletions extcap/randpktdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,13 @@ int main(int argc, char *argv[])
char* help_url;
char* help_header = NULL;

g_set_prgname("randpktdump");

/* Initialize log handler early so we can have proper logging during startup. */
ws_log_init(NULL);
ws_log_init("randpktdump", NULL);

cmdarg_err_init(randpktdump_cmdarg_err, randpktdump_cmdarg_err);

/* Command line options are parsed too late to configure logging, do it
manually. */
if (ws_log_parse_args(&argc, argv, cmdarg_err) != 0)
return EXIT_FAILURE;
/* Early logging command-line initialization. */
ws_log_parse_args(&argc, argv, vcmdarg_err, EXIT_FAILURE);

/*
* Get credential information for later use.
Expand Down
3 changes: 3 additions & 0 deletions extcap/sdjournal.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@ int main(int argc, char **argv)
char* help_url;
char* help_header = NULL;

/* Initialize log handler early so we can have proper logging during startup. */
ws_log_init("sdjournal", NULL);

/*
* Get credential information for later use.
*/
Expand Down
3 changes: 3 additions & 0 deletions extcap/sshdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ int main(int argc, char *argv[])
gboolean noprom = FALSE;
gchar* interface_description = g_strdup("SSH remote capture");

/* Initialize log handler early so we can have proper logging during startup. */
ws_log_init("sshdump", NULL);

sshdump_extcap_interface = g_path_get_basename(argv[0]);

/*
Expand Down
3 changes: 3 additions & 0 deletions extcap/udpdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@ int main(int argc, char *argv[])
char* payload = NULL;
char* port_msg = NULL;

/* Initialize log handler early so we can have proper logging during startup. */
ws_log_init("udpdump", NULL);

/*
* Get credential information for later use.
*/
Expand Down
4 changes: 4 additions & 0 deletions fuzz/fuzzshark.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <wsutil/filesystem.h>
#include <wsutil/privileges.h>
#include <wsutil/report_message.h>
#include <wsutil/wslog.h>
#include <version_info.h>

#include <wiretap/wtap.h>
Expand Down Expand Up @@ -234,6 +235,9 @@ fuzz_init(int argc _U_, char **argv)
g_setenv("WIRESHARK_DEBUG_WMEM_OVERRIDE", "simple", 0);
g_setenv("G_SLICE", "always-malloc", 0);

/* Initialize log handler early so we can have proper logging during startup. */
ws_log_init("fuzzshark", NULL);

cmdarg_err_init(fuzzshark_cmdarg_err, fuzzshark_cmdarg_err_cont);

/*
Expand Down
7 changes: 7 additions & 0 deletions mergecap.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <wsutil/privileges.h>
#include <wsutil/strnatcmp.h>
#include <wsutil/ws_assert.h>
#include <wsutil/wslog.h>

#include <cli_main.h>
#include <version_info.h>
Expand Down Expand Up @@ -227,8 +228,14 @@ main(int argc, char *argv[])
idb_merge_mode mode = IDB_MERGE_MODE_MAX;
merge_progress_callback_t cb;

/* Initialize log handler early so we can have proper logging during startup. */
ws_log_init("mergecap", NULL);

cmdarg_err_init(mergecap_cmdarg_err, mergecap_cmdarg_err_cont);

/* Early logging command-line initialization. */
ws_log_parse_args(&argc, argv, vcmdarg_err, 1);

#ifdef _WIN32
create_app_running_mutex();
#endif /* _WIN32 */
Expand Down
11 changes: 9 additions & 2 deletions randpkt.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#endif

#include <wsutil/report_message.h>
#include <wsutil/wslog.h>

/*
* If we have getopt_long() in the system library, include <getopt.h>.
Expand Down Expand Up @@ -137,6 +138,14 @@ main(int argc, char *argv[])
{0, 0, 0, 0 }
};

/* Initialize log handler early so we can have proper logging during startup. */
ws_log_init("randpkt", NULL);

cmdarg_err_init(randpkt_cmdarg_err, randpkt_cmdarg_err_cont);

/* Early logging command-line initialization. */
ws_log_parse_args(&argc, argv, vcmdarg_err, INVALID_OPTION);

/*
* Get credential information for later use.
*/
Expand All @@ -158,8 +167,6 @@ main(int argc, char *argv[])

wtap_init(TRUE);

cmdarg_err_init(randpkt_cmdarg_err, randpkt_cmdarg_err_cont);

#ifdef _WIN32
create_app_running_mutex();
#endif /* _WIN32 */
Expand Down
10 changes: 3 additions & 7 deletions rawshark.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,17 +449,13 @@ main(int argc, char *argv[])
setlocale(LC_ALL, "");
#endif

g_set_prgname("rawshark");

/* Initialize log handler early so we can have proper logging during startup. */
ws_log_init(NULL);
ws_log_init("rawshark", NULL);

cmdarg_err_init(rawshark_cmdarg_err, rawshark_cmdarg_err_cont);

/* Command line options are parsed too late to configure logging, do it
manually. */
if (ws_log_parse_args(&argc, argv, cmdarg_err) != 0)
return INVALID_OPTION;
/* Early logging command-line initialization. */
ws_log_parse_args(&argc, argv, vcmdarg_err, INVALID_OPTION);

/* Initialize the version information. */
ws_init_version_info("Rawshark (Wireshark)", NULL,
Expand Down
7 changes: 7 additions & 0 deletions reordercap.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#endif

#include <wsutil/report_message.h>
#include <wsutil/wslog.h>

#include "ui/failure_message.h"

Expand Down Expand Up @@ -207,8 +208,14 @@ main(int argc, char *argv[])
char *infile;
const char *outfile;

/* Initialize log handler early so we can have proper logging during startup. */
ws_log_init("reordercap", NULL);

cmdarg_err_init(reordercap_cmdarg_err, reordercap_cmdarg_err_cont);

/* Early logging command-line initialization. */
ws_log_parse_args(&argc, argv, vcmdarg_err, INVALID_OPTION);

/* Initialize the version information. */
ws_init_version_info("Reordercap (Wireshark)", NULL, NULL, NULL);

Expand Down
10 changes: 3 additions & 7 deletions sharkd.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,13 @@ main(int argc, char *argv[])
cfile_close_failure_message
};

g_set_prgname("sharkd");

/* Initialize log handler early so we can have proper logging during startup. */
ws_log_init(NULL);
ws_log_init("sharkd", NULL);

cmdarg_err_init(sharkd_cmdarg_err, sharkd_cmdarg_err_cont);

/* Command line options are parsed too late to configure logging, do it
manually. */
if (ws_log_parse_args(&argc, argv, cmdarg_err) != 0)
return INIT_FAILED;
/* Early logging command-line initialization. */
ws_log_parse_args(&argc, argv, vcmdarg_err, INIT_FAILED);

/*
* Get credential information for later use, and drop privileges
Expand Down
4 changes: 4 additions & 0 deletions text2pcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
#include <cli_main.h>
#include <version_info.h>
#include <wsutil/inet_addr.h>
#include <wsutil/wslog.h>

#ifdef _WIN32
#include <io.h> /* for _setmode */
Expand Down Expand Up @@ -1864,6 +1865,9 @@ main(int argc, char *argv[])
{
int ret = EXIT_SUCCESS;

/* Initialize log handler early so we can have proper logging during startup. */
ws_log_init("text2pcap", NULL);

#ifdef _WIN32
create_app_running_mutex();
#endif /* _WIN32 */
Expand Down
10 changes: 3 additions & 7 deletions tshark.c
Original file line number Diff line number Diff line change
Expand Up @@ -775,17 +775,13 @@ main(int argc, char *argv[])
setlocale(LC_ALL, "");
#endif

g_set_prgname("tshark");

/* Initialize log handler early so we can have proper logging during startup. */
ws_log_init(NULL);
ws_log_init("tshark", NULL);

cmdarg_err_init(tshark_cmdarg_err, tshark_cmdarg_err_cont);

/* Command line options are parsed too late to configure logging, do it
manually. */
if (ws_log_parse_args(&argc, argv, cmdarg_err) != 0)
return INVALID_OPTION;
/* Early logging command-line initialization. */
ws_log_parse_args(&argc, argv, vcmdarg_err, INVALID_OPTION);

ws_debug("tshark started with %d args", argc);

Expand Down
Loading

0 comments on commit 759bb23

Please sign in to comment.