Commit 2a38dc74 authored by Guy Harris's avatar Guy Harris

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/17506Reviewed-by: 's avatarGuy Harris <guy@alum.mit.edu>
parent ae877942
......@@ -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();
......
......@@ -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();
......
......@@ -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();
......
......@@ -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();
......
......@@ -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();
......
......@@ -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);
}
}
......
......@@ -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 *,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment