diff options
author | Guy Harris <guy@alum.mit.edu> | 2016-09-05 16:26:29 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2016-09-05 23:27:02 +0000 |
commit | 2a38dc74ede3eba69f0d73b61f1735a4036528c1 (patch) | |
tree | c03b1f72dcd66c54907d546a45c28315ba35fd27 | |
parent | ae877942ea507128d3191e17075a26b86e52615d (diff) |
Have scan_plugins() take an argument specify what to do on load failures.
That's a less gross hack to suppress load failures due to not having
libwiretap than providing a no-op failure-message routine, as it at
least allows other code using a failure-message routine, such as
cmdarg_err() and routines that call it, to be used.
We really should put libwiretap and libwireshark plugins into separate
subdirectories of the plugin directories, and avoid even looking at
libwireshark plugins in programs that don't use libwireshark.
Change-Id: I0a6ec01ecb4e718ed36233cfaf638a317f839a73
Reviewed-on: https://code.wireshark.org/review/17506
Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r-- | capinfos.c | 18 | ||||
-rw-r--r-- | captype.c | 18 | ||||
-rw-r--r-- | dftest.c | 2 | ||||
-rw-r--r-- | editcap.c | 17 | ||||
-rw-r--r-- | mergecap.c | 18 | ||||
-rw-r--r-- | randpkt.c | 19 | ||||
-rw-r--r-- | reordercap.c | 18 | ||||
-rw-r--r-- | tfshark.c | 2 | ||||
-rw-r--r-- | tshark.c | 2 | ||||
-rw-r--r-- | ui/gtk/main.c | 2 | ||||
-rw-r--r-- | wireshark-qt.cpp | 2 | ||||
-rw-r--r-- | wsutil/plugins.c | 29 | ||||
-rw-r--r-- | wsutil/plugins.h | 6 |
13 files changed, 98 insertions, 55 deletions
diff --git a/capinfos.c b/capinfos.c index 4b8debab94..9d0901da4d 100644 --- a/capinfos.c +++ b/capinfos.c @@ -1375,14 +1375,14 @@ print_usage(FILE *output) #ifdef HAVE_PLUGINS /* - * Don't report failures to load plugins because most (non-wiretap) plugins - * *should* fail to load (because we're not linked against libwireshark and - * dissector plugins need libwireshark). + * General errors are reported with an console message in capinfos. */ static void -failure_message(const char *msg_format _U_, va_list ap _U_) +failure_message(const char *msg_format, va_list ap) { - return; + fprintf(stderr, "capinfos: "); + vfprintf(stderr, msg_format, ap); + fprintf(stderr, "\n"); } #endif @@ -1466,8 +1466,12 @@ main(int argc, char *argv[]) init_report_err(failure_message, NULL, NULL, NULL); /* Scan for plugins. This does *not* call their registration routines; - that's done later. */ - scan_plugins(); + that's done later. + + Don't report failures to load plugins because most (non-wiretap) + plugins *should* fail to load (because we're not linked against + libwireshark and dissector plugins need libwireshark). */ + scan_plugins(DONT_REPORT_LOAD_FAILURE); /* Register all libwiretap plugin modules. */ register_all_wiretap_modules(); @@ -70,14 +70,14 @@ print_usage(FILE *output) #ifdef HAVE_PLUGINS /* - * Don't report failures to load plugins because most (non-wiretap) plugins - * *should* fail to load (because we're not linked against libwireshark and - * dissector plugins need libwireshark). + * General errors are reported with an console message in captype. */ static void -failure_message(const char *msg_format _U_, va_list ap _U_) +failure_message(const char *msg_format, va_list ap) { - return; + fprintf(stderr, "captype: "); + vfprintf(stderr, msg_format, ap); + fprintf(stderr, "\n"); } #endif @@ -141,8 +141,12 @@ main(int argc, char *argv[]) init_report_err(failure_message,NULL,NULL,NULL); /* Scan for plugins. This does *not* call their registration routines; - that's done later. */ - scan_plugins(); + that's done later. + + Don't report failures to load plugins because most (non-wiretap) + plugins *should* fail to load (because we're not linked against + libwireshark and dissector plugins need libwireshark). */ + scan_plugins(DONT_REPORT_LOAD_FAILURE); /* Register all libwiretap plugin modules. */ register_all_wiretap_modules(); @@ -88,7 +88,7 @@ main(int argc, char **argv) /* Scan for plugins. This does *not* call their registration routines; that's done later. */ - scan_plugins(); + scan_plugins(REPORT_LOAD_FAILURE); #endif /* Register all dissectors; we must do this before checking for the @@ -894,13 +894,14 @@ framenum_compare(gconstpointer a, gconstpointer b, gpointer user_data _U_) #ifdef HAVE_PLUGINS /* - * Don't report failures to load plugins because most (non-wiretap) plugins - * *should* fail to load (because we're not linked against libwireshark and - * dissector plugins need libwireshark). + * General errors are reported with an console message in editcap. */ static void -failure_message(const char *msg_format _U_, va_list ap _U_) +failure_message(const char *msg_format, va_list ap) { + fprintf(stderr, "editcap: "); + vfprintf(stderr, msg_format, ap); + fprintf(stderr, "\n"); } #endif @@ -1011,8 +1012,12 @@ main(int argc, char *argv[]) init_report_err(failure_message,NULL,NULL,NULL); /* Scan for plugins. This does *not* call their registration routines; - that's done later. */ - scan_plugins(); + that's done later. + + Don't report failures to load plugins because most (non-wiretap) + plugins *should* fail to load (because we're not linked against + libwireshark and dissector plugins need libwireshark). */ + scan_plugins(DONT_REPORT_LOAD_FAILURE); /* Register all libwiretap plugin modules. */ register_all_wiretap_modules(); diff --git a/mergecap.c b/mergecap.c index c6c97619ef..089ef0254d 100644 --- a/mergecap.c +++ b/mergecap.c @@ -129,14 +129,14 @@ string_elem_print(gpointer data, gpointer not_used _U_) #ifdef HAVE_PLUGINS /* - * Don't report failures to load plugins because most (non-wiretap) plugins - * *should* fail to load (because we're not linked against libwireshark and - * dissector plugins need libwireshark). + * General errors are reported with an console message in mergecap. */ static void -failure_message(const char *msg_format _U_, va_list ap _U_) +failure_message(const char *msg_format, va_list ap) { - return; + fprintf(stderr, "mergecap: "); + vfprintf(stderr, msg_format, ap); + fprintf(stderr, "\n"); } #endif @@ -310,8 +310,12 @@ main(int argc, char *argv[]) init_report_err(failure_message,NULL,NULL,NULL); /* Scan for plugins. This does *not* call their registration routines; - that's done later. */ - scan_plugins(); + that's done later. + + Don't report failures to load plugins because most (non-wiretap) + plugins *should* fail to load (because we're not linked against + libwireshark and dissector plugins need libwireshark).*/ + scan_plugins(DONT_REPORT_LOAD_FAILURE); /* Register all libwiretap plugin modules. */ register_all_wiretap_modules(); @@ -49,14 +49,14 @@ #ifdef HAVE_PLUGINS /* - * Don't report failures to load plugins because most (non-wiretap) plugins - * *should* fail to load (because we're not linked against libwireshark and - * dissector plugins need libwireshark). + * General errors are reported with an console message in randpkt. */ static void -failure_message(const char *msg_format _U_, va_list ap _U_) +failure_message(const char *msg_format, va_list ap) { - return; + fprintf(stderr, "randpkt: "); + vfprintf(stderr, msg_format, ap); + fprintf(stderr, "\n"); } #endif @@ -141,8 +141,13 @@ main(int argc, char **argv) init_report_err(failure_message,NULL,NULL,NULL); /* Scan for plugins. This does *not* call their registration routines; - that's done later. */ - scan_plugins(); + that's done later. + + Don't report failures to load plugins because most + (non-wiretap) plugins *should* fail to load (because + we're not linked against libwireshark and dissector + plugins need libwireshark). */ + scan_plugins(DONT_REPORT_LOAD_FAILURE); /* Register all libwiretap plugin modules. */ register_all_wiretap_modules(); diff --git a/reordercap.c b/reordercap.c index 206a4888c8..e01f43c5fd 100644 --- a/reordercap.c +++ b/reordercap.c @@ -148,14 +148,14 @@ frames_compare(gconstpointer a, gconstpointer b) #ifdef HAVE_PLUGINS /* - * Don't report failures to load plugins because most (non-wiretap) plugins - * *should* fail to load (because we're not linked against libwireshark and - * dissector plugins need libwireshark). + * General errors are reported with an console message in reordercap. */ static void -failure_message(const char *msg_format _U_, va_list ap _U_) +failure_message(const char *msg_format, va_list ap) { - return; + fprintf(stderr, "reordercap: "); + vfprintf(stderr, msg_format, ap); + fprintf(stderr, "\n"); } #endif @@ -231,8 +231,12 @@ main(int argc, char *argv[]) init_report_err(failure_message,NULL,NULL,NULL); /* Scan for plugins. This does *not* call their registration routines; - that's done later. */ - scan_plugins(); + that's done later. + + Don't report failures to load plugins because most (non-wiretap) + plugins *should* fail to load (because we're not linked against + libwireshark and dissector plugins need libwireshark). */ + scan_plugins(DONT_REPORT_LOAD_FAILURE); /* Register all libwiretap plugin modules. */ register_all_wiretap_modules(); @@ -509,7 +509,7 @@ main(int argc, char *argv[]) /* Scan for plugins. This does *not* call their registration routines; that's done later. */ - scan_plugins(); + scan_plugins(REPORT_LOAD_FAILURE); #endif @@ -791,7 +791,7 @@ main(int argc, char *argv[]) /* Scan for plugins. This does *not* call their registration routines; that's done later. */ - scan_plugins(); + scan_plugins(REPORT_LOAD_FAILURE); /* Register all libwiretap plugin modules. */ register_all_wiretap_modules(); diff --git a/ui/gtk/main.c b/ui/gtk/main.c index 01de65a40c..5c17338400 100644 --- a/ui/gtk/main.c +++ b/ui/gtk/main.c @@ -2292,7 +2292,7 @@ main(int argc, char *argv[]) /* Scan for plugins. This does *not* call their registration routines; that's done later. */ - scan_plugins(); + scan_plugins(REPORT_LOAD_FAILURE); /* Register all libwiretap plugin modules. */ register_all_wiretap_modules(); diff --git a/wireshark-qt.cpp b/wireshark-qt.cpp index 22ceaa9d64..8a1564af71 100644 --- a/wireshark-qt.cpp +++ b/wireshark-qt.cpp @@ -542,7 +542,7 @@ int main(int argc, char *argv[]) /* Scan for plugins. This does *not* call their registration routines; that's done later. */ - scan_plugins(); + scan_plugins(REPORT_LOAD_FAILURE); /* Register all libwiretap plugin modules. */ register_all_wiretap_modules(); diff --git a/wsutil/plugins.c b/wsutil/plugins.c index 8a390948f5..f2da1f57d2 100644 --- a/wsutil/plugins.c +++ b/wsutil/plugins.c @@ -143,7 +143,7 @@ call_plugin_callback(gpointer data, gpointer user_data) } static void -plugins_scan_dir(const char *dirname) +plugins_scan_dir(const char *dirname, plugin_load_failure_mode mode) { #define FILENAME_LEN 1024 WS_DIR *dir; /* scanned directory */ @@ -175,8 +175,21 @@ plugins_scan_dir(const char *dirname) dirname, name); if ((handle = g_module_open(filename, G_MODULE_BIND_LOCAL)) == NULL) { - report_failure("Couldn't load module %s: %s", filename, - g_module_error()); + /* + * Only report load failures if we were asked to. + * + * XXX - we really should put different types of plugins + * (libwiretap, libwireshark) in different subdirectories, + * give libwiretap and libwireshark init routines that + * load the plugins, and have them scan the appropriate + * subdirectories so tha we don't even *try* to, for + * example, load libwireshark plugins in programs that + * only use libwiretap. + */ + if (mode == REPORT_LOAD_FAILURE) { + report_failure("Couldn't load module %s: %s", filename, + g_module_error()); + } continue; } @@ -241,7 +254,7 @@ plugins_scan_dir(const char *dirname) * Scan for plugins. */ void -scan_plugins(void) +scan_plugins(plugin_load_failure_mode mode) { const char *plugin_dir; const char *name; @@ -264,7 +277,7 @@ scan_plugins(void) { if ((dir = ws_dir_open(plugin_dir, 0, NULL)) != NULL) { - plugins_scan_dir(plugin_dir); + plugins_scan_dir(plugin_dir, mode); while ((file = ws_dir_read_name(dir)) != NULL) { name = ws_dir_get_name(file); @@ -290,14 +303,14 @@ scan_plugins(void) plugin_dir_path = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", plugin_dir, name); } - plugins_scan_dir(plugin_dir_path); + plugins_scan_dir(plugin_dir_path, mode); g_free(plugin_dir_path); } ws_dir_close(dir); } } else - plugins_scan_dir(plugin_dir); + plugins_scan_dir(plugin_dir, mode); /* * If the program wasn't started with special privileges, @@ -310,7 +323,7 @@ scan_plugins(void) if (!started_with_special_privs()) { plugins_pers_dir = get_plugins_pers_dir(); - plugins_scan_dir(plugins_pers_dir); + plugins_scan_dir(plugins_pers_dir, mode); g_free(plugins_pers_dir); } } diff --git a/wsutil/plugins.h b/wsutil/plugins.h index 1d5f0b6fd9..677c6d3f0b 100644 --- a/wsutil/plugins.h +++ b/wsutil/plugins.h @@ -34,7 +34,11 @@ extern "C" { typedef gboolean (*plugin_callback)(GModule *handle); -WS_DLL_PUBLIC void scan_plugins(void); +typedef enum { + REPORT_LOAD_FAILURE, + DONT_REPORT_LOAD_FAILURE +} plugin_load_failure_mode; +WS_DLL_PUBLIC void scan_plugins(plugin_load_failure_mode mode); WS_DLL_PUBLIC void add_plugin_type(const char *type, plugin_callback callback); typedef void (*plugin_description_callback)(const char *, const char *, const char *, const char *, |