X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=cli%2Fbabeltrace.c;h=821772e191b048a2b444da3018e94444eb8b885d;hb=a8ff38ef4b08728cd1bb93ae66a888dfbda4fbb2;hp=cb8492f2acfd9630f1b5d1feb8c8d5653ac2f075;hpb=0982a26d7f4ad134fbef954f87d0fd5d7bb60af4;p=babeltrace.git diff --git a/cli/babeltrace.c b/cli/babeltrace.c index cb8492f2..821772e1 100644 --- a/cli/babeltrace.c +++ b/cli/babeltrace.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -626,25 +627,33 @@ end: } static -void add_to_loaded_plugins(struct bt_plugin **plugins) +void add_to_loaded_plugins(struct bt_plugin_set *plugin_set) { - while (*plugins) { - struct bt_plugin *plugin = *plugins; - /* Check if it's already loaded (from another path). */ + int i; + int count; + + count = bt_plugin_set_get_plugin_count(plugin_set); + assert(count >= 0); + + for (i = 0; i < count; i++) { + struct bt_plugin *plugin = + bt_plugin_set_get_plugin(plugin_set, i); struct bt_plugin *loaded_plugin = find_plugin(bt_plugin_get_name(plugin)); + assert(plugin); + if (loaded_plugin) { printf_verbose("Not loading plugin `%s`: already loaded from `%s`\n", bt_plugin_get_path(plugin), bt_plugin_get_path(loaded_plugin)); - BT_PUT(loaded_plugin); - BT_PUT(plugin); + bt_put(loaded_plugin); } else { - /* Transfer ownership to global array. */ - g_ptr_array_add(loaded_plugins, plugin); + /* Add to global array. */ + g_ptr_array_add(loaded_plugins, bt_get(plugin)); } - *(plugins++) = NULL; + + bt_put(plugin); } } @@ -662,7 +671,7 @@ int load_dynamic_plugins(struct bt_value *plugin_paths) for (i = 0; i < nr_paths; i++) { struct bt_value *plugin_path_value = NULL; const char *plugin_path; - struct bt_plugin **plugins; + struct bt_plugin_set *plugin_set; plugin_path_value = bt_value_array_get(plugin_paths, i); if (bt_value_string_get(plugin_path_value, @@ -671,17 +680,16 @@ int load_dynamic_plugins(struct bt_value *plugin_paths) continue; } - plugins = bt_plugin_create_all_from_dir(plugin_path, false); - if (!plugins) { + plugin_set = bt_plugin_create_all_from_dir(plugin_path, false); + if (!plugin_set) { printf_debug("Unable to dynamically load plugins from path %s.\n", plugin_path); BT_PUT(plugin_path_value); continue; } - add_to_loaded_plugins(plugins); - free(plugins); - + add_to_loaded_plugins(plugin_set); + bt_put(plugin_set); BT_PUT(plugin_path_value); } end: @@ -692,17 +700,17 @@ static int load_static_plugins(void) { int ret = 0; - struct bt_plugin **plugins; + struct bt_plugin_set *plugin_set; - plugins = bt_plugin_create_all_from_static(); - if (!plugins) { + plugin_set = bt_plugin_create_all_from_static(); + if (!plugin_set) { printf_debug("Unable to load static plugins.\n"); ret = -1; goto end; } - add_to_loaded_plugins(plugins); - free(plugins); + add_to_loaded_plugins(plugin_set); + bt_put(plugin_set); end: return ret; }