From 5d4cba3d05c64cc8c3a4041d11cc26f6c4fb9977 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 24 Feb 2016 17:30:06 -0500 Subject: [PATCH] Don't load plug-ins recursively by default MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- include/babeltrace/plugin/component-factory.h | 15 +++++++++- lib/plugin-system/component-factory.c | 30 ++++++++++++++----- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/include/babeltrace/plugin/component-factory.h b/include/babeltrace/plugin/component-factory.h index 02414c284..c3190cb1f 100644 --- a/include/babeltrace/plugin/component-factory.h +++ b/include/babeltrace/plugin/component-factory.h @@ -109,6 +109,19 @@ extern struct bt_component_class *bt_component_factory_get_component_class( const char *plugin_name, enum bt_component_type type, const char *component_name); +/** + * Load and register Babeltrace plugins under a given path. + * + * Path will be traversed if it is a directory, otherwise only the provided file + * will be loaded. + * + * @param factory A component factory instance + * @param path A path to a file or directory + * @returns One of #bt_component_factory_status values + */ +extern enum bt_component_factory_status bt_component_factory_load( + struct bt_component_factory *factory, const char *path); + /** * Recursively load and register Babeltrace plugins under a given path. * @@ -119,7 +132,7 @@ extern struct bt_component_class *bt_component_factory_get_component_class( * @param path A path to a file or directory * @returns One of #bt_component_factory_status values */ -extern enum bt_component_factory_status bt_component_factory_load( +extern enum bt_component_factory_status bt_component_factory_load_recursive( struct bt_component_factory *factory, const char *path); extern enum bt_component_factory_status diff --git a/lib/plugin-system/component-factory.c b/lib/plugin-system/component-factory.c index 65840d4ca..6d7602917 100644 --- a/lib/plugin-system/component-factory.c +++ b/lib/plugin-system/component-factory.c @@ -145,8 +145,8 @@ end: static enum bt_component_factory_status -bt_component_factory_load_dir_recursive(struct bt_component_factory *factory, - const char *path) +bt_component_factory_load_dir(struct bt_component_factory *factory, + const char *path, bool recurse) { DIR *directory = NULL; struct dirent *entry = NULL, *result = NULL; @@ -211,9 +211,9 @@ bt_component_factory_load_dir_recursive(struct bt_component_factory *factory, continue; } - if (S_ISDIR(st.st_mode)) { - ret = bt_component_factory_load_dir_recursive(factory, - file_path); + if (S_ISDIR(st.st_mode) && recurse) { + ret = bt_component_factory_load_dir(factory, + file_path, true); if (ret != BT_COMPONENT_FACTORY_STATUS_OK) { goto end; } @@ -352,8 +352,10 @@ match: return bt_get(component_class); } -enum bt_component_factory_status bt_component_factory_load( - struct bt_component_factory *factory, const char *path) +static +enum bt_component_factory_status _bt_component_factory_load( + struct bt_component_factory *factory, const char *path, + bool recursive) { enum bt_component_factory_status ret = BT_COMPONENT_FACTORY_STATUS_OK; @@ -368,7 +370,7 @@ enum bt_component_factory_status bt_component_factory_load( } if (g_file_test(path, G_FILE_TEST_IS_DIR)) { - ret = bt_component_factory_load_dir_recursive(factory, path); + ret = bt_component_factory_load_dir(factory, path, recursive); } else if (g_file_test(path, G_FILE_TEST_IS_REGULAR) || g_file_test(path, G_FILE_TEST_IS_SYMLINK)) { ret = bt_component_factory_load_file(factory, path); @@ -380,6 +382,18 @@ end: return ret; } +enum bt_component_factory_status bt_component_factory_load_recursive( + struct bt_component_factory *factory, const char *path) +{ + return _bt_component_factory_load(factory, path, true); +} + +enum bt_component_factory_status bt_component_factory_load( + struct bt_component_factory *factory, const char *path) +{ + return _bt_component_factory_load(factory, path, false); +} + static enum bt_component_factory_status add_component_class(struct bt_component_factory *factory, const char *name, -- 2.34.1