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.

(cherry picked from commit c7f66cf934)

Conflicts:
	tshark.c
This commit is contained in:
Gerald Combs 2021-02-09 15:48:08 -08:00 committed by Gerald Combs
parent 90ed3ff952
commit 21f9f3f1f2
2 changed files with 43 additions and 5 deletions

View File

@ -5829,8 +5829,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

@ -711,6 +711,7 @@ main(int argc, char *argv[])
{0, 0, 0, 0 }
};
gboolean arg_error = FALSE;
gboolean has_extcap_options = FALSE;
int err;
gchar *err_info;
@ -834,6 +835,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?
@ -851,10 +857,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 */
@ -943,11 +965,19 @@ main(int argc, char *argv[])
#ifdef HAVE_PLUGINS
register_all_plugin_tap_listeners();
#endif
extcap_register_preferences();
/* Register all tap listeners. */
for (tap_reg_t *t = tap_reg_listener; t->cb_func != NULL; t++) {
t->cb_func();
}
/*
* 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);
srt_table_iterate_tables(register_srt_tables, NULL);
@ -1295,8 +1325,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;