From c7f66cf93491fd3ed9ca03fe967a692d64546aa2 Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Tue, 9 Feb 2021 15:48:08 -0800 Subject: [PATCH] TShark: Load extcap preferences only when needed. In our first pass through our options, look for ones that might require extcap. Call extcap_register_preferences() only when that's the case. Warn about missing extcap preferences only when we've loaded them. --- epan/prefs.c | 12 ++++++++++-- tshark.c | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/epan/prefs.c b/epan/prefs.c index c00491992e..6379db9fd5 100644 --- a/epan/prefs.c +++ b/epan/prefs.c @@ -5892,8 +5892,16 @@ set_pref(gchar *pref_name, const gchar *value, void *private_data _U_, } } } - if (pref == NULL) - return PREFS_SET_NO_SUCH_PREF; /* no such preference */ + if (pref == NULL ) { + if (strcmp(module->name, "extcap") == 0 && g_list_length(module->prefs) <= 1) { + /* + * Assume that we've skipped extcap preference registration + * and that only extcap.gui_save_on_start is loaded. + */ + return PREFS_SET_OK; + } + return PREFS_SET_NO_SUCH_PREF; /* no such preference */ + } type = pref->type; if (IS_PREF_OBSOLETE(type)) { diff --git a/tshark.c b/tshark.c index 75acf90b48..00ef29f2c4 100644 --- a/tshark.c +++ b/tshark.c @@ -712,6 +712,7 @@ main(int argc, char *argv[]) {0, 0, 0, 0 } }; gboolean arg_error = FALSE; + gboolean has_extcap_options = FALSE; int err; gchar *err_info; @@ -835,6 +836,11 @@ main(int argc, char *argv[]) * *after* epan_init() gets called, so that the dissectors have had a * chance to register their preferences. * + * Spawning a bunch of extcap processes can delay program startup, + * particularly on Windows. Check to see if we have any options that + * might require extcap and set has_extcap_options = TRUE if that's + * the case. + * * XXX - can we do this all with one getopt_long() call, saving the * arguments we can't handle until after initializing libwireshark, * and then process them after initializing libwireshark? @@ -852,10 +858,26 @@ main(int argc, char *argv[]) goto clean_exit; } break; + case 'G': + if (g_str_has_suffix(optarg, "prefs") || strcmp(optarg, "folders") == 0) { + has_extcap_options = TRUE; + } + break; + case 'i': + has_extcap_options = TRUE; + break; + case 'o': + if (g_str_has_prefix(optarg, "extcap.")) { + has_extcap_options = TRUE; + } + break; case 'P': /* Print packet summary info even when writing to a file */ print_packet_info = TRUE; print_summary = TRUE; break; + case 'r': /* Read capture file x */ + cf_name = g_strdup(optarg); + break; case 'O': /* Only output these protocols */ output_only = g_strdup(optarg); /* FALLTHROUGH */ @@ -940,7 +962,13 @@ main(int argc, char *argv[]) register_all_tap_listeners(tap_reg_listener); - extcap_register_preferences(); + /* + * An empty cf_name indicates that we're capturing, and we might + * be doing so on an extcap interface. + */ + if (has_extcap_options || !cf_name) { + extcap_register_preferences(); + } conversation_table_set_gui_info(init_iousers); hostlist_table_set_gui_info(init_hostlists); @@ -1290,8 +1318,8 @@ main(int argc, char *argv[]) quiet = TRUE; really_quiet = TRUE; break; - case 'r': /* Read capture file x */ - cf_name = g_strdup(optarg); + case 'r': + /* already processed; just ignore it now */ break; case 'R': /* Read file filter */ rfilter = optarg;