From 50ad9320ef034cba9c1b997d57c69e09f1152d87 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Mon, 29 May 2017 14:47:52 -0400 Subject: [PATCH] Remove warnings when using bt_plugin_create_all_from_dir() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit bt_plugin_create_all_from_dir() expects an existing directory, otherwise it fails with a WARN-level log message because it's the user's responsibility to ensure this. A few functions of the library and the CLI call this with nonexisting paths, resulting in warnings under normal usage (for example, default plugin search paths which do not exist; this is not an error nor a warning). This patch fixes this by testing the existence of the paths passed to bt_plugin_create_all_from_dir() with g_file_test(), skipping (usually with a VERBOSE-level message) when it's not the case. Signed-off-by: Philippe Proulx Signed-off-by: Jérémie Galarneau --- cli/babeltrace.c | 13 ++++++++++ lib/plugin/plugin-so.c | 54 ++++++++++++++++++++++++++++++++++++++---- lib/plugin/plugin.c | 11 +++++++++ 3 files changed, 74 insertions(+), 4 deletions(-) diff --git a/cli/babeltrace.c b/cli/babeltrace.c index 9de233bc..fbf61141 100644 --- a/cli/babeltrace.c +++ b/cli/babeltrace.c @@ -581,6 +581,19 @@ int load_dynamic_plugins(struct bt_value *plugin_paths) plugin_path_value = bt_value_array_get(plugin_paths, i); bt_value_string_get(plugin_path_value, &plugin_path); assert(plugin_path); + + /* + * Skip this if the directory does not exist because + * bt_plugin_create_all_from_dir() expects an existing + * directory. + */ + if (!g_file_test(plugin_path, G_FILE_TEST_IS_DIR)) { + BT_LOGV("Skipping nonexistent directory path: " + "path=\"%s\"", plugin_path); + BT_PUT(plugin_path_value); + continue; + } + plugin_set = bt_plugin_create_all_from_dir(plugin_path, false); if (!plugin_set) { BT_LOGD("Unable to load dynamic plugins: path=\"%s\"", diff --git a/lib/plugin/plugin-so.c b/lib/plugin/plugin-so.c index 38f88746..d4be8ca3 100644 --- a/lib/plugin/plugin-so.c +++ b/lib/plugin/plugin-so.c @@ -210,7 +210,14 @@ struct bt_plugin_so_shared_lib_handle *bt_plugin_so_shared_lib_handle_create( shared_lib_handle->module = g_module_open(path, 0); if (!shared_lib_handle->module) { - BT_LOGW("Cannot open GModule: %s: path=\"%s\"", + /* + * DEBUG-level logging because we're only _trying_ to + * open this file as a Babeltrace plugin: if it's not, + * it's not an error. And because this can be tried + * during bt_plugin_create_all_from_dir(), it's not even + * a warning. + */ + BT_LOGD("Cannot open GModule: %s: path=\"%s\"", g_module_error(), path); goto error; } @@ -368,6 +375,13 @@ enum bt_plugin_status bt_plugin_so_init( cur_attr->value.version.extra); break; default: + /* + * WARN-level logging because this should not + * happen with the appropriate ABI version. If + * we're here, we know that for the reported + * version of the ABI, this attribute is + * unknown. + */ BT_LOGW("Ignoring unknown plugin descriptor attribute: " "plugin-path=\"%s\", plugin-name=\"%s\", " "attr-type-name=\"%s\", attr-type-id=%d", @@ -467,6 +481,15 @@ enum bt_plugin_status bt_plugin_so_init( cur_cc_descr_attr->value.notif_iter_seek_time_method; break; default: + /* + * WARN-level logging because + * this should not happen with + * the appropriate ABI version. + * If we're here, we know that + * for the reported version of + * the ABI, this attribute is + * unknown. + */ BT_LOGW("Ignoring unknown component class descriptor attribute: " "plugin-path=\"%s\", " "plugin-name=\"%s\", " @@ -539,6 +562,13 @@ enum bt_plugin_status bt_plugin_so_init( cc_full_descr->descriptor->methods.sink.consume); break; default: + /* + * WARN-level logging because this should not + * happen with the appropriate ABI version. If + * we're here, we know that for the reported + * version of the ABI, this component class type + * is unknown. + */ BT_LOGW("Ignoring unknown component class type: " "plugin-path=\"%s\", plugin-name=\"%s\", " "comp-class-name=\"%s\", comp-class-type=%d", @@ -842,7 +872,15 @@ struct bt_plugin_set *bt_plugin_so_create_all_from_sections( descriptor->name, descriptor->major, descriptor->minor); if (descriptor->major > __BT_PLUGIN_VERSION_MAJOR) { - BT_LOGW("Unknown ABI major version: abi-major=%d", + /* + * DEBUG-level logging because we're only + * _trying_ to open this file as a compatible + * Babeltrace plugin: if it's not, it's not an + * error. And because this can be tried during + * bt_plugin_create_all_from_dir(), it's not + * even a warning. + */ + BT_LOGD("Unknown ABI major version: abi-major=%d", descriptor->major); goto error; } @@ -861,7 +899,15 @@ struct bt_plugin_set *bt_plugin_so_create_all_from_sections( attrs_end, cc_descriptors_begin, cc_descriptors_end, cc_descr_attrs_begin, cc_descr_attrs_end); if (status < 0) { - BT_LOGW_STR("Cannot initialize SO plugin object from sections."); + /* + * DEBUG-level logging because we're only + * _trying_ to open this file as a compatible + * Babeltrace plugin: if it's not, it's not an + * error. And because this can be tried during + * bt_plugin_create_all_from_dir(), it's not + * even a warning. + */ + BT_LOGD_STR("Cannot initialize SO plugin object from sections."); BT_PUT(plugin); goto error; } @@ -956,7 +1002,7 @@ struct bt_plugin_set *bt_plugin_so_create_all_from_file(const char *path) shared_lib_handle = bt_plugin_so_shared_lib_handle_create(path); if (!shared_lib_handle) { - BT_LOGW_STR("Cannot create shared library handle."); + BT_LOGD_STR("Cannot create shared library handle."); goto end; } diff --git a/lib/plugin/plugin.c b/lib/plugin/plugin.c index 9518b8ea..a1a522ec 100644 --- a/lib/plugin/plugin.c +++ b/lib/plugin/plugin.c @@ -269,6 +269,16 @@ struct bt_plugin *bt_plugin_find(const char *plugin_name) BT_PUT(plugin_set); + /* + * Skip this if the directory does not exist because + * bt_plugin_create_all_from_dir() would log a warning. + */ + if (!g_file_test(dir->str, G_FILE_TEST_IS_DIR)) { + BT_LOGV("Skipping nonexistent directory path: " + "path=\"%s\"", dir->str); + continue; + } + /* bt_plugin_create_all_from_dir() logs details/errors */ plugin_set = bt_plugin_create_all_from_dir(dir->str, BT_FALSE); if (!plugin_set) { @@ -456,6 +466,7 @@ enum bt_plugin_status bt_plugin_create_append_all_from_dir( if (strcmp(result->d_name, ".") == 0 || strcmp(result->d_name, "..") == 0) { + /* Obviously not logging this */ continue; } -- 2.34.1