- size_t path_len;
- struct bt_plugin **plugins = NULL;
- struct __bt_plugin_descriptor const * const *descriptors_begin = NULL;
- struct __bt_plugin_descriptor const * const *descriptors_end = NULL;
- struct __bt_plugin_descriptor_attribute const * const *attrs_begin = NULL;
- struct __bt_plugin_descriptor_attribute const * const *attrs_end = NULL;
- struct __bt_plugin_component_class_descriptor const * const *cc_descriptors_begin = NULL;
- struct __bt_plugin_component_class_descriptor const * const *cc_descriptors_end = NULL;
- struct __bt_plugin_component_class_descriptor_attribute const * const *cc_descr_attrs_begin = NULL;
- struct __bt_plugin_component_class_descriptor_attribute const * const *cc_descr_attrs_end = NULL;
- bool is_libtool_wrapper = false, is_shared_object = false;
- struct bt_plugin_shared_lib_handle *shared_lib_handle = NULL;
-
- if (!path) {
- goto end;
- }
-
- path_len = strlen(path);
- if (path_len <= PLUGIN_SUFFIX_LEN) {
- goto end;
- }
-
- path_len++;
- /*
- * Check if the file ends with a known plugin file type suffix (i.e. .so
- * or .la on Linux).
- */
- is_libtool_wrapper = !strncmp(LIBTOOL_PLUGIN_SUFFIX,
- path + path_len - LIBTOOL_PLUGIN_SUFFIX_LEN,
- LIBTOOL_PLUGIN_SUFFIX_LEN);
- is_shared_object = !strncmp(NATIVE_PLUGIN_SUFFIX,
- path + path_len - NATIVE_PLUGIN_SUFFIX_LEN,
- NATIVE_PLUGIN_SUFFIX_LEN);
- if (!is_shared_object && !is_libtool_wrapper) {
- /* Name indicates that this is not a plugin file. */
- goto end;
- }
-
- shared_lib_handle = bt_plugin_shared_lib_handle_create(path);
- if (!shared_lib_handle) {
- goto end;
- }
-
- if (!g_module_symbol(shared_lib_handle->module, "__start___bt_plugin_descriptors",
- (gpointer *) &descriptors_begin)) {
- printf_verbose("Unable to resolve plugin symbol %s from %s\n",
- "__start___bt_plugin_descriptors",
- g_module_name(shared_lib_handle->module));
- goto end;
- }
-
- if (!g_module_symbol(shared_lib_handle->module, "__stop___bt_plugin_descriptors",
- (gpointer *) &descriptors_end)) {
- printf_verbose("Unable to resolve plugin symbol %s from %s\n",
- "__stop___bt_plugin_descriptors",
- g_module_name(shared_lib_handle->module));
- goto end;
- }
-
- if (!g_module_symbol(shared_lib_handle->module, "__start___bt_plugin_descriptor_attributes",
- (gpointer *) &attrs_begin)) {
- printf_verbose("Unable to resolve plugin symbol %s from %s\n",
- "__start___bt_plugin_descriptor_attributes",
- g_module_name(shared_lib_handle->module));
- }
-
- if (!g_module_symbol(shared_lib_handle->module, "__stop___bt_plugin_descriptor_attributes",
- (gpointer *) &attrs_end)) {
- printf_verbose("Unable to resolve plugin symbol %s from %s\n",
- "__stop___bt_plugin_descriptor_attributes",
- g_module_name(shared_lib_handle->module));
- }
-
- if ((!!attrs_begin - !!attrs_end) != 0) {
- printf_verbose("Found __start___bt_plugin_descriptor_attributes or __stop___bt_plugin_descriptor_attributes symbol, but not both in %s\n",
- g_module_name(shared_lib_handle->module));
- goto end;
- }
-
- if (!g_module_symbol(shared_lib_handle->module, "__start___bt_plugin_component_class_descriptors",
- (gpointer *) &cc_descriptors_begin)) {
- printf_verbose("Unable to resolve plugin symbol %s from %s\n",
- "__start___bt_plugin_component_class_descriptors",
- g_module_name(shared_lib_handle->module));
- }
-
- if (!g_module_symbol(shared_lib_handle->module, "__stop___bt_plugin_component_class_descriptors",
- (gpointer *) &cc_descriptors_end)) {
- printf_verbose("Unable to resolve plugin symbol %s from %s\n",
- "__stop___bt_plugin_component_class_descriptors",
- g_module_name(shared_lib_handle->module));
- }