static int plibltpdl_foreachfile(const char *search_path, int (*func)(const char *filename, void *data), void *data) { assert(search_path); assert(func); int ret = lt_dlforeachfile(search_path, func, data); return (0 == ret) ? PMIX_SUCCESS : PMIX_ERROR; }
/* Opens the plugins directory provided and calls * scrapePlugin for the name */ int loadPluginsDirectory () { /* Plugin directory is set by autotools using user-defined prefix */ #ifndef PLUGIN_DIR doLog (ERROR, LOG_COMP, _("PLUGIN_DIR not provided at compile time.")); return -1; #endif return lt_dlforeachfile (PLUGIN_PATH, scrapePlugin, NULL); }
/* * Cache all the filenames found in a specific directory. If * flush_cache==1, then empty the cache first. */ int cci_plugins_recache_files(const char *dir, int flush_cache) { if (flush_cache) { cci_argv_free(cci_plugins_filename_cache); cci_plugins_filename_cache = NULL; } if (0 != lt_dlforeachfile(dir, save_filename, NULL)) { fprintf(stderr, "lt_dlforeachfile failed: %s\n", lt_dlerror()); return CCI_ERROR; } return CCI_SUCCESS; }
void plugins_init(const char *path) { char *plugins_path; lt_dladvise advise; if (path && !strcmp(path, "none")) { return; } if (!(plugins_path = path ? xstrdup(path) : xstrdup(ovs_pluginsdir()))) { VLOG_ERR("Failed to allocate plugins path"); return; } if (lt_dlinit() || lt_dlsetsearchpath(plugins_path) || lt_dladvise_init(&advise)) { VLOG_ERR("ltdl initializations: %s", lt_dlerror()); goto err_init; } if (!(interface_id = lt_dlinterface_register("ovs-plugin", NULL))) { VLOG_ERR("lt_dlinterface_register: %s", lt_dlerror()); goto err_interface_register; } if (lt_dladvise_global(&advise) || lt_dladvise_ext (&advise) || lt_dlforeachfile(lt_dlgetsearchpath(), &plugins_open_plugin, &advise)) { VLOG_ERR("ltdl setting advise: %s", lt_dlerror()); goto err_set_advise; } VLOG_INFO("Successfully initialized all plugins"); return; err_set_advise: lt_dlinterface_free(interface_id); err_interface_register: if (lt_dladvise_destroy(&advise)) { VLOG_ERR("destroying ltdl advise%s", lt_dlerror()); return; } err_init: free(plugins_path); }
/** * \brief Load system ports * * \param list a #GPPortInfoList * * Searches the system for io-drivers and appends them to the list. You would * normally call this function once after #gp_port_info_list_new and then * use this list in order to supply #gp_port_set_info with parameters or to do * autodetection. * * \return a gphoto2 error code **/ int gp_port_info_list_load (GPPortInfoList *list) { const char *iolibs_env = getenv(IOLIBDIR_ENV); const char *iolibs = (iolibs_env != NULL)?iolibs_env:IOLIBS; int result; CHECK_NULL (list); gp_log (GP_LOG_DEBUG, "gphoto2-port-info-list", _("Using ltdl to load io-drivers from '%s'..."), iolibs); lt_dlinit (); lt_dladdsearchdir (iolibs); result = lt_dlforeachfile (iolibs, foreach_func, list); lt_dlexit (); if (result < 0) return (result); return (GP_OK); }
gregorio_plugin *gregorio_plugin_load (const char *path, const char *id) { struct load_params params; params.id = id; params.plugin = malloc (sizeof(gregorio_plugin)); if (params.plugin == NULL) { return NULL; } /* Find the first plugin in path matching params.id */ lt_dlforeachfile (path, do_load_plugin, (void *)¶ms); if (params.plugin->handle == NULL) { free(params.plugin); return NULL; } return params.plugin; }
static void load_plugins (int debug_info) { int ix; char *names; if (debug_info) printf ("Loading plugins from %s...\n", PLUGIN_DIR); if (lt_dlinit ()) fatal ("lt_dlinit() failed: %s", lt_dlerror ()); if (lt_dlforeachfile (PLUGIN_DIR, <_load_plugin, &debug_info)) fatal ("Can't load plugins: %s", lt_dlerror ()); if (plugins_num == 0) fatal ("No decoder plugins have been loaded!"); for (ix = 0; ix < plugins_num; ix += 1) default_decoder_list[ix] = ix; names = list_decoder_names (default_decoder_list, plugins_num); logit ("Loaded %d decoders:%s", plugins_num, names); free (names); }
int gp_abilities_list_load_dir (CameraAbilitiesList *list, const char *dir, GPContext *context) { CameraLibraryIdFunc id; CameraLibraryAbilitiesFunc ab; CameraText text; int ret, x, old_count, new_count; unsigned int i, p; const char *filename; CameraList *flist; int count; lt_dlhandle lh; CHECK_NULL (list && dir); gp_log (GP_LOG_DEBUG, "gphoto2-abilities-list", "Using ltdl to load camera libraries from '%s'...", dir); CHECK_RESULT (gp_list_new (&flist)); ret = gp_list_reset (flist); if (ret < GP_OK) { gp_list_free (flist); return ret; } if (1) { /* a new block in which we can define a temporary variable */ foreach_data_t foreach_data = { NULL, GP_OK }; foreach_data.list = flist; lt_dlinit (); lt_dladdsearchdir (dir); ret = lt_dlforeachfile (dir, foreach_func, &foreach_data); lt_dlexit (); if (ret != 0) { gp_list_free (flist); gp_log (GP_LOG_ERROR, "gp-abilities-list", "Internal error looking for camlibs (%d)", ret); gp_context_error (context, _("Internal error looking for camlibs. " "(path names too long?)")); return (foreach_data.result!=GP_OK)?foreach_data.result:GP_ERROR; } } count = gp_list_count (flist); if (count < GP_OK) { gp_list_free (flist); return ret; } gp_log (GP_LOG_DEBUG, "gp-abilities-list", "Found %i " "camera drivers.", count); lt_dlinit (); p = gp_context_progress_start (context, count, _("Loading camera drivers from '%s'..."), dir); for (i = 0; i < count; i++) { ret = gp_list_get_name (flist, i, &filename); if (ret < GP_OK) { gp_list_free (flist); return ret; } lh = lt_dlopenext (filename); if (!lh) { gp_log (GP_LOG_DEBUG, "gphoto2-abilities-list", "Failed to load '%s': %s.", filename, lt_dlerror ()); continue; } /* camera_id */ id = lt_dlsym (lh, "camera_id"); if (!id) { gp_log (GP_LOG_DEBUG, "gphoto2-abilities-list", "Library '%s' does not seem to " "contain a camera_id function: %s", filename, lt_dlerror ()); lt_dlclose (lh); continue; } /* * Make sure the camera driver hasn't been * loaded yet. */ if (id (&text) != GP_OK) { lt_dlclose (lh); continue; } if (gp_abilities_list_lookup_id (list, text.text) >= 0) { lt_dlclose (lh); continue; } /* camera_abilities */ ab = lt_dlsym (lh, "camera_abilities"); if (!ab) { gp_log (GP_LOG_DEBUG, "gphoto2-abilities-list", "Library '%s' does not seem to " "contain a camera_abilities function: " "%s", filename, lt_dlerror ()); lt_dlclose (lh); continue; } old_count = gp_abilities_list_count (list); if (old_count < 0) { lt_dlclose (lh); continue; } if (ab (list) != GP_OK) { lt_dlclose (lh); continue; } lt_dlclose (lh); new_count = gp_abilities_list_count (list); if (new_count < 0) continue; /* Copy in the core-specific information */ for (x = old_count; x < new_count; x++) { strcpy (list->abilities[x].id, text.text); strcpy (list->abilities[x].library, filename); } gp_context_progress_update (context, p, i); if (gp_context_cancel (context) == GP_CONTEXT_FEEDBACK_CANCEL) { lt_dlexit (); gp_list_free (flist); return (GP_ERROR_CANCEL); } } gp_context_progress_stop (context, p); lt_dlexit (); gp_list_free (flist); return (GP_OK); }
/* * Open up all directories in a given path and search for components of * the specified type (and possibly of a given name). * * Note that we use our own path iteration functionality (vs. ltdl's * lt_dladdsearchdir() functionality) because we need to look at * companion .ompi_info files in the same directory as the library to * generate dependencies, etc. If we use the plain lt_dlopen() * functionality, we would not get the directory name of the file * finally opened in recursive dependency traversals. */ static void find_dyn_components(const char *path, const char *type_name, const char **names, bool include_mode, opal_list_t *found_components) { int i, len; char *path_to_use = NULL, *dir, *end; component_file_item_t *file; opal_list_item_t *cur; char prefix[32 + MCA_BASE_MAX_TYPE_NAME_LEN], *basename; /* If path is NULL, iterate over the set of directories specified by the MCA param mca_base_component_path. If path is not NULL, then use that as the path. */ if (NULL == path) { if (NULL != mca_base_component_path) { path_to_use = strdup (mca_base_component_path); } else { /* If there's no path, then there's nothing to search -- we're done */ return; } if (NULL == path_to_use) { /* out of memory */ return; } } else { path_to_use = strdup(path); } /* If we haven't done so already, iterate over all the files in the directories in the path and make a master array of all the matching filenames that we find. Save the filenames in an argv-style array. Re-scan do this if the mca_component_path has changed. */ if (NULL == found_filenames || (NULL != last_path_to_use && 0 != strcmp(path_to_use, last_path_to_use))) { if (NULL != found_filenames) { opal_argv_free(found_filenames); found_filenames = NULL; free(last_path_to_use); last_path_to_use = NULL; } if (NULL == last_path_to_use) { last_path_to_use = strdup(path_to_use); } dir = path_to_use; if (NULL != dir) { do { end = strchr(dir, OPAL_ENV_SEP); if (NULL != end) { *end = '\0'; } if ((0 == strcmp(dir, "USER_DEFAULT") || 0 == strcmp(dir, "USR_DEFAULT")) && NULL != mca_base_user_default_path) { if (0 != lt_dlforeachfile(mca_base_user_default_path, save_filename, NULL)) { break; } } else if (0 == strcmp(dir, "SYS_DEFAULT") || 0 == strcmp(dir, "SYSTEM_DEFAULT")) { if (0 != lt_dlforeachfile(mca_base_system_default_path, save_filename, NULL)) { break; } } else { if (0 != lt_dlforeachfile(dir, save_filename, NULL)) { break; } } dir = end + 1; } while (NULL != end); } } /* Look through the list of found files and find those that match the desired framework name */ snprintf(prefix, sizeof(prefix) - 1, component_template, type_name); len = strlen(prefix); OBJ_CONSTRUCT(&found_files, opal_list_t); for (i = 0; NULL != found_filenames && NULL != found_filenames[i]; ++i) { basename = strrchr(found_filenames[i], '/'); if (NULL == basename) { basename = found_filenames[i]; } else { basename += 1; } if (0 != strncmp(basename, prefix, len)) { continue; } /* We found a match; save all the relevant details in the found_files list */ file = OBJ_NEW(component_file_item_t); if (NULL == file) { return; } strncpy(file->type, type_name, MCA_BASE_MAX_TYPE_NAME_LEN); file->type[MCA_BASE_MAX_TYPE_NAME_LEN] = '\0'; strncpy(file->name, basename + len, MCA_BASE_MAX_COMPONENT_NAME_LEN); file->name[MCA_BASE_MAX_COMPONENT_NAME_LEN] = '\0'; strncpy(file->basename, basename, OPAL_PATH_MAX); file->basename[OPAL_PATH_MAX] = '\0'; strncpy(file->filename, found_filenames[i], OPAL_PATH_MAX); file->filename[OPAL_PATH_MAX] = '\0'; file->status = UNVISITED; opal_list_append(&found_files, (opal_list_item_t *) file); } /* Iterate through all the filenames that we found that matched the framework we were looking for. Since one component may [try to] call another to be loaded, only try to load the UNVISITED files. Also, ignore the return code -- basically, give every file one chance to try to load. If they load, great. If not, great. */ for (cur = opal_list_get_first(&found_files); opal_list_get_end(&found_files) != cur; cur = opal_list_get_next(cur)) { file = (component_file_item_t *) cur; if( UNVISITED == file->status ) { bool op = true; file->status = CHECKING_CYCLE; op = use_component(include_mode, names, file->name); if( true == op ) { open_component(file, found_components); } } } /* So now we have a final list of loaded components. We can free all the file information. */ for (cur = opal_list_remove_first(&found_files); NULL != cur; cur = opal_list_remove_first(&found_files)) { OBJ_RELEASE(cur); } OBJ_DESTRUCT(&found_files); /* All done, now let's cleanup */ free(path_to_use); }
/* * Open up all directories in a given path and search for components of * the specified type (and possibly of a given name). * * Note that we use our own path iteration functionality (vs. ltdl's * lt_dladdsearchdir() functionality) because we need to look at * companion .ompi_info files in the same directory as the library to * generate dependencies, etc. If we use the plain lt_dlopen() * functionality, we would not get the directory name of the file * finally opened in recursive dependency traversals. */ static void find_dyn_components(const char *path, const char *type_name, const char **name, bool include_mode, opal_list_t *found_components) { ltfn_data_holder_t params; char *path_to_use, *dir, *end; component_file_item_t *file; opal_list_item_t *cur; strncpy(params.type, type_name, MCA_BASE_MAX_TYPE_NAME_LEN); params.type[MCA_BASE_MAX_TYPE_NAME_LEN] = '\0'; params.name[0] = '\0'; /* If path is NULL, iterate over the set of directories specified by the MCA param mca_base_component_path. If path is not NULL, then use that as the path. */ if (NULL == path) { mca_base_param_lookup_string(mca_base_param_component_path, &path_to_use); if (NULL == path_to_use) { /* If there's no path, then there's nothing to search -- we're done */ return; } } else { path_to_use = strdup(path); } /* Iterate over all the files in the directories in the path and make a master array of all the matching filenames that we find. */ OBJ_CONSTRUCT(&found_files, opal_list_t); dir = path_to_use; if (NULL != dir) { do { end = strchr(dir, OPAL_ENV_SEP); if (NULL != end) { *end = '\0'; } if (0 != lt_dlforeachfile(dir, save_filename, ¶ms)) { break; } dir = end + 1; } while (NULL != end); } /* Iterate through all the filenames that we found. Since one component may [try to] call another to be loaded, only try to load the UNVISITED files. Also, ignore the return code -- basically, give every file one chance to try to load. If they load, great. If not, great. */ for (cur = opal_list_get_first(&found_files); opal_list_get_end(&found_files) != cur; cur = opal_list_get_next(cur)) { file = (component_file_item_t *) cur; if( UNVISITED == file->status ) { bool op = true; file->status = CHECKING_CYCLE; op = use_component(include_mode, name, file->name); if( true == op ) { open_component(file, found_components); } } } /* So now we have a final list of loaded components. We can free all the file information. */ for (cur = opal_list_remove_first(&found_files); NULL != cur; cur = opal_list_remove_first(&found_files)) { OBJ_RELEASE(cur); } /* All done, now let's cleanup */ free(path_to_use); OBJ_DESTRUCT(&found_files); }
/* * Open up all directories in a given path and search for components of * the specified type (and possibly of a given name). * * Note that we use our own path iteration functionality (vs. ltdl's * lt_dladdsearchdir() functionality) because we need to look at * companion .ompi_info files in the same directory as the library to * generate dependencies, etc. If we use the plain lt_dlopen() * functionality, we would not get the directory name of the file * finally opened in recursive dependency traversals. */ static void find_dyn_components(const char *path, const char *type_name, const char *name, opal_list_t *found_components) { ltfn_data_holder_t params; char *path_to_use, *dir, *end, *param; component_file_item_t *file; opal_list_item_t *cur; strcpy(params.type, type_name); if (NULL == name) { params.name[0] = '\0'; opal_output_verbose(40, 0, "mca: base: component_find: looking for all dynamic %s MCA components", type_name, NULL); } else { strcpy(params.name, name); opal_output_verbose(40, 0, "mca: base: component_find: looking for dynamic %s MCA component named \"%s\"", type_name, name, NULL); } /* If path is NULL, iterate over the set of directories specified by the MCA param mca_base_component_path. If path is not NULL, then use that as the path. */ param = NULL; if (NULL == path) { mca_base_param_lookup_string(mca_base_param_component_path, ¶m); if (NULL == param) { /* If there's no path, then there's nothing to search -- we're done */ return; } else { path_to_use = strdup(param); } } else { path_to_use = strdup(path); } /* Iterate over all the files in the directories in the path and make a master array of all the matching filenames that we find. */ OBJ_CONSTRUCT(&found_files, opal_list_t); dir = path_to_use; if (NULL != dir) { do { end = strchr(dir, OPAL_ENV_SEP); if (NULL != end) { *end = '\0'; } if (0 != lt_dlforeachfile(dir, save_filename, ¶ms)) { break; } dir = end + 1; } while (NULL != end); } /* Iterate through all the filenames that we found. Since one component may [try to] call another to be loaded, only try to load the UNVISITED files. Also, ignore the return code -- basically, give every file one chance to try to load. If they load, great. If not, great. */ for (cur = opal_list_get_first(&found_files); opal_list_get_end(&found_files) != cur; cur = opal_list_get_next(cur)) { file = (component_file_item_t *) cur; if (UNVISITED == file->status) { open_component(file, found_components); } } /* So now we have a final list of loaded components. We can free all the file information. */ for (cur = opal_list_remove_first(&found_files); NULL != cur; cur = opal_list_remove_first(&found_files)) { OBJ_RELEASE(cur); } /* All done */ if (NULL != param) { free(param); } if (NULL != path_to_use) { free(path_to_use); } OBJ_DESTRUCT(&found_files); }