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.
This commit is contained in:
Gerald Combs 2021-02-09 15:48:08 -08:00 committed by AndersBroman
parent 28937e9022
commit c7f66cf934
2 changed files with 41 additions and 5 deletions

View File

@ -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)) {

View File

@ -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;