Remove warnings when using bt_plugin_create_all_from_dir()
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 29 May 2017 18:47:52 +0000 (14:47 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 9 Jun 2017 20:58:12 +0000 (16:58 -0400)
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 <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
cli/babeltrace.c
lib/plugin/plugin-so.c
lib/plugin/plugin.c

index 9de233bc1672718ec3bc3c31cd029b469a3e0b60..fbf611417130c5c47c49879ce1764b278b7925ef 100644 (file)
@@ -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\"",
index 38f887463b0478f66031e11d5a0f512c851ce6bc..d4be8ca375c12a98fed4252eee69dffb3c8290f9 100644 (file)
@@ -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;
        }
 
index 9518b8eaa4e3578e7e9cdc79a887a3ee92ba8078..a1a522ecb4cc6068692e8519a0769bc82be6ce6e 100644 (file)
@@ -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;
                }
 
This page took 0.028486 seconds and 4 git commands to generate.