static char * get_first_module_on_dir(const char *dir_name) { char *result = NULL; char path[PATH_MAX], install_rootdir[PATH_MAX]; struct stat st; int r; r = sol_util_get_rootdir(install_rootdir, sizeof(install_rootdir)); SOL_INT_CHECK(r, >= (int)sizeof(install_rootdir), NULL); SOL_INT_CHECK(r, < 0, NULL); r = snprintf(path, sizeof(path), "%s%s", install_rootdir, dir_name); SOL_INT_CHECK(r, >= (int)sizeof(path), NULL); SOL_INT_CHECK(r, < 0, NULL); if (stat(path, &st) || !S_ISDIR(st.st_mode)) { SOL_DBG("Invalid update module dir: %s", path); return NULL; } if (!sol_util_iterate_dir(path, iterate_dir_cb, &result)) return NULL; return result; }
static bool _load_mux(const char *name) { #ifdef ENABLE_DYNAMIC_MODULES int r; void *handle; char path[PATH_MAX], install_rootdir[PATH_MAX] = { 0 }; const struct sol_pin_mux *p_sym; r = sol_util_get_rootdir(install_rootdir, sizeof(install_rootdir)); SOL_INT_CHECK(r, >= (int)sizeof(install_rootdir), false); r = snprintf(path, sizeof(path), "%s%s/%s.so", install_rootdir, PINMUXDIR, name); SOL_INT_CHECK(r, >= (int)sizeof(path), false); SOL_INT_CHECK(r, < 0, false); handle = dlopen(path, RTLD_LAZY | RTLD_LOCAL | RTLD_NODELETE); if (!handle) { SOL_INF("Could not load platform pin multiplexer '%s': %s", path, dlerror()); return true; // Not find a mux isn't necessarily an error, so we are returning true here } p_sym = dlsym(handle, "SOL_PIN_MUX"); SOL_NULL_CHECK_MSG_GOTO(p_sym, error, "Could not find symbol SOL_PIN_MUX in module '%s': %s", path, dlerror()); #ifndef SOL_NO_API_VERSION if (p_sym->api_version != SOL_PIN_MUX_API_VERSION) { SOL_WRN("Mux '%s' has incorrect api_version: %lu expected %lu", path, p_sym->api_version, SOL_PIN_MUX_API_VERSION); goto error; } #endif if (dl_handle) dlclose(dl_handle); mux = p_sym; dl_handle = handle; SOL_INF("Loaded pin multiplexer '%s' from '%s'", mux->plat_name, path); return true; error: dlclose(handle); return false; #else return true; #endif }