G_MODULE_EXPORT gboolean swfdec_mozilla_make_sure_this_thing_stays_in_memory (void) { static gboolean inited = FALSE; GModule *module; gpointer check; if (inited) return TRUE; if (!g_module_supported ()) return FALSE; module = g_module_open (PLUGIN_FILE, 0); if (module == NULL) return FALSE; /* now load this function name to be sure it we've loaded ourselves */ if (!g_module_symbol (module, "swfdec_mozilla_make_sure_this_thing_stays_in_memory", &check) || check != swfdec_mozilla_make_sure_this_thing_stays_in_memory) { g_module_close (module); return FALSE; } g_module_make_resident (module); g_module_close (module); inited = TRUE; return TRUE; }
const char * g_module_check_init (GModule *module) { g_module_make_resident (module); return NULL; }
static int qemu_rbd_load_libs(void) { if (librbd_loaded) { return 0; } if (!g_module_supported()) { error_report("modules are not supported on this platform: %s", g_module_error()); return -1; } librbd_handle = g_module_open("/usr/lib64/qemu/librbd.so.1", 0); if (!librbd_handle) { error_report("error loading librbd: %s", g_module_error()); return -1; } /* * Due to c++ templates used in librbd/librados and their * dependencies, and linker duplicate trimming rules, closing * librbd would leave it mapped. Make this explicit. */ g_module_make_resident(librbd_handle); if (qemu_rbd_set_mandatory_functions() < 0) { return -1; } qemu_rbd_set_optional_functions(); librbd_loaded = true; return 0; }
/* FIXME: It would be better to just fix the flags using RTLD_NOLOAD because * the libraries are surely loaded. */ static gboolean reload_libraries(void) { /* Do not do it on Win32 because the libs must be fully resolved there and * because the library names are different (with -0). */ #ifndef G_OS_WIN32 static const gchar *const gwyddion_libs[] = { "libgwyddion2", "libgwyprocess2", "libgwydraw2", "libgwydgets2", "libgwymodule2", "libgwyapp2", }; guint i; for (i = 0; i < G_N_ELEMENTS(gwyddion_libs); i++) { gchar *filename = g_strconcat(gwyddion_libs[i], ".", GWY_SHARED_LIBRARY_EXTENSION, NULL); GModule *modhandle = g_module_open(filename, G_MODULE_BIND_LAZY); if (!modhandle) { gchar *excstr = g_strdup_printf("Cannot dlopen() %s.", filename); PyErr_SetString(PyExc_ImportError, excstr); g_free(excstr); return FALSE; } g_module_make_resident(modhandle); g_free(filename); } #endif return TRUE; }
static gboolean pluma_object_module_load (GTypeModule *gmodule) { PlumaObjectModule *module = PLUMA_OBJECT_MODULE (gmodule); PlumaObjectModuleRegisterFunc register_func; gchar *path; pluma_debug_message (DEBUG_PLUGINS, "Loading %s module from %s", module->priv->module_name, module->priv->path); path = g_module_build_path (module->priv->path, module->priv->module_name); g_return_val_if_fail (path != NULL, FALSE); pluma_debug_message (DEBUG_PLUGINS, "Module filename: %s", path); module->priv->library = g_module_open (path, G_MODULE_BIND_LAZY); g_free (path); if (module->priv->library == NULL) { g_warning ("%s: %s", module->priv->module_name, g_module_error()); return FALSE; } /* extract symbols from the lib */ if (!g_module_symbol (module->priv->library, module->priv->type_registration, (void *) ®ister_func)) { g_warning ("%s: %s", module->priv->module_name, g_module_error()); g_module_close (module->priv->library); return FALSE; } /* symbol can still be NULL even though g_module_symbol * returned TRUE */ if (register_func == NULL) { g_warning ("Symbol '%s' should not be NULL", module->priv->type_registration); g_module_close (module->priv->library); return FALSE; } module->priv->type = register_func (gmodule); if (module->priv->type == 0) { g_warning ("Invalid object contained by module %s", module->priv->module_name); return FALSE; } if (module->priv->resident) { g_module_make_resident (module->priv->library); } return TRUE; }
G_MODULE_EXPORT void gegl_op_json_register_type (GTypeModule *module) { #else G_MODULE_EXPORT const GeglModuleInfo * gegl_module_query (GTypeModule *module) { return &modinfo; } G_MODULE_EXPORT gboolean gegl_module_register (GTypeModule *module) { #endif /* Ensure the module, or shared libs it pulls in is not unloaded * This because when GTypes are registered (like for json-glib), * all referenced data must stay in memory until process exit */ g_module_make_resident (GEGL_MODULE (module)->module); json_register_operations (module); #ifndef GEGL_OP_BUNDLE return TRUE; #endif }
static gboolean load_storage_module (const char *module_name) { GModule *module; char *filename; filename = g_module_build_path (PLUGINDIR, module_name); module = g_module_open (filename, 0); g_free (filename); if (module == NULL) return FALSE; if (!g_module_symbol (module, "init", (gpointer *) &store.init) || !g_module_symbol (module, "deinit", (gpointer *) &store.deinit) || !g_module_symbol (module, "print_data_save", (gpointer *) &store.print_data_save) || !g_module_symbol (module, "print_data_load", (gpointer *) &store.print_data_load) || !g_module_symbol (module, "print_data_delete", (gpointer *) &store.print_data_delete) || !g_module_symbol (module, "discover_prints", (gpointer *) &store.discover_prints)) { g_module_close (module); return FALSE; } g_module_make_resident (module); return TRUE; }
static GMod* gmod_new (const char* module_name, gboolean is_resident) { if(!module_name) return NULL; GMod* gmod = g_new0(GMod, 1); gmod->name = g_strdup(module_name); if(!gmod->name) { g_free(gmod); return NULL; } gmod->path = g_module_build_path (MODULE_PATH_PREFIX, gmod->name); if(!gmod->path){ g_free(gmod->name); g_free(gmod); gmod->name = NULL; return NULL; } gmod->module = g_module_open(gmod->path, G_MODULE_BIND_LAZY); if(!gmod->module){ g_free(gmod->name); g_free(gmod->path); g_free(gmod); gmod->name = NULL; gmod->path = NULL; return NULL; } if(is_resident) g_module_make_resident(gmod->module); return gmod; }
static void _add_app( const gchar *name, const gchar *path) { guint i; gboolean ok; qio_app_cb cb; GString *full_path = qev_buffer_get(); guint *magic_num = NULL; struct app *app = g_slice_alloc0(sizeof(*app)); app->name = g_strdup(name); if (strspn(path, PATH_STARTERS) == 0) { g_string_printf(full_path, "%s/%s", PATH_LIB_DIR, path); } else { g_string_assign(full_path, path); } app->mod = g_module_open(full_path->str, G_MODULE_BIND_LOCAL); ASSERT(app->mod != NULL, "Could not open app %s: %s", name, g_module_error()); /* * For config: unloading modules causes segfaults on exit because the * modules can be closed an removed from memory. Keep them in memory at * all times: not like they can be removed at runtime anyway. */ g_module_make_resident(app->mod); for (i = 0; i < _apps->len; i++) { struct app *oapp = g_ptr_array_index(_apps, i); ASSERT(app->mod != oapp->mod, "Duplicate app detected %s (%s).", name, full_path->str); } ok = g_module_symbol(app->mod, "__qio_is_app", (void*)&magic_num) && *magic_num == QIO_MAGIC_NUM; ASSERT(ok, "Loaded module is not a QuickIO app: %s (%s)", name, full_path->str) #define X(fn) \ ASSERT(g_module_symbol(app->mod, "__qio_app_" G_STRINGIFY(fn), (void*)&cb), \ "App missing default QuickIO function %s: %s (%s)", \ "__qio_app_" G_STRINGIFY(fn), name, full_path->str); \ app->fn = cb; CALLBACKS #undef X ASSERT(app->init(), "Could not initialize app (%s): init() failed", name); g_ptr_array_add(_apps, app); qev_buffer_put(full_path); }
/** * gwy_module_register_types: * @errorlist: (allow-none): * Location to store possible errors. * Errors from %GWY_MODULE_ERROR domain can occur. * * Registers extension types from all modules that were loaded but their types * were not registered yet. * * Returns: The number of new types registered. **/ guint gwy_module_register_types(GwyErrorList **errorlist) { GPtrArray *todo_list = gather_unregistered_modules(); if (!todo_list) return 0; GHashTable *libraries_seen = g_hash_table_new(g_str_hash, g_str_equal); guint count = 0; for (guint i = 0; i < todo_list->len; i++) { ModuleInfo *modinfo = g_ptr_array_index(todo_list, i); const GwyModuleInfo *module_info = modinfo->module_info; for (guint j = 0; j < module_info->ntypes; j++) { GError *error = NULL; if (register_one_type(module_info->types + j, modinfo->qname, &error)) { count++; } if (error) { // TODO: log the error somewhere gwy_error_list_propagate(errorlist, error); } } if (modinfo->from_library) { const gchar *path = g_module_name(modinfo->mod); if (!g_hash_table_lookup(libraries_seen, path)) { g_module_make_resident(modinfo->mod); g_hash_table_insert(libraries_seen, (gpointer)path, GUINT_TO_POINTER(TRUE)); } } else { g_module_make_resident(modinfo->mod); } modinfo->did_type_registration = TRUE; } g_hash_table_unref(libraries_seen); g_ptr_array_free(todo_list, TRUE); return count; }
gboolean plugin_load_module(const gchar *module_name, GlobalConfig *cfg, CfgArgs *args) { GModule *mod; static GModule *main_module_handle; gboolean (*init_func)(GlobalConfig *cfg, CfgArgs *args); gchar *module_init_func; const gchar *mp; gchar *p; if (!main_module_handle) main_module_handle = g_module_open(NULL, 0); module_init_func = g_strdup_printf("%s_module_init", module_name); for (p = module_init_func; *p; p++) { if ((*p) == '-') *p = '_'; } if (g_module_symbol(main_module_handle, module_init_func, (gpointer *) &init_func)) { /* already linked in, no need to load explicitly */ goto call_init; } if (cfg->lexer) mp = cfg_args_get(cfg->lexer->globals, "module-path"); else mp = NULL; if (!mp) mp = module_path; mod = plugin_dlopen_module(module_name, mp); if (!mod) { g_free(module_init_func); return FALSE; } g_module_make_resident(mod); if (!g_module_symbol(mod, module_init_func, (gpointer *) &init_func)) { msg_error("Error finding init function in module", evt_tag_str("module", module_name), evt_tag_str("symbol", module_init_func), evt_tag_str("error", g_module_error()), NULL); g_free(module_init_func); return FALSE; } call_init: g_free(module_init_func); return (*init_func)(cfg, args); }
const gchar* g_module_check_init(GModule *module) { g_module_make_resident(module); GPARTS_TYPE_MYSQL_DATABASE; GPARTS_TYPE_MYSQL_FACTORY; GPARTS_TYPE_MYSQL_RESULT; return NULL; }
const gchar* g_module_check_init (GModule *module) { /* * We can't handle being unloaded due to the gobject * types we register */ g_module_make_resident (module); return NULL; }
G_MODULE_EXPORT const gchar * g_module_check_init (GModule *module) { /* FIXME Until mail is split into a module library and a * reusable shared library, prevent the module from * being unloaded. Unloading the module resets all * static variables, which screws up foo_get_type() * functions among other things. */ g_module_make_resident (module); return NULL; }
gboolean load_symbols(const char *module, ...) { GModule *mod; gboolean found_all = TRUE; va_list args; mod = g_module_open(module, static_cast<GModuleFlags>(G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL)); if (!mod) return FALSE; procman_debug("Found %s", module); va_start(args, module); while (1) { const char *name; void **symbol; name = va_arg(args, char*); if (!name) break; symbol = va_arg(args, void**); if (g_module_symbol(mod, name, symbol)) { procman_debug("Loaded %s from %s", name, module); } else { procman_debug("Could not load %s from %s", name, module); found_all = FALSE; break; } } va_end(args); if (found_all) g_module_make_resident(mod); else g_module_close(mod); return found_all; }
static bool load_module (std::string &name, std::map<std::string, KurentoModule *> &modules) { GModule *module; KurentoModule *kurento_module = NULL; std::string module_name; module = g_module_open (name.c_str(), G_MODULE_BIND_LAZY); if (module == NULL) { return false; } if (!g_module_symbol (module, KURENTO_MODULE_DESCRIPTOR, (gpointer *) &kurento_module) ) { GST_ERROR ("Error loading symbol %s from library %s", KURENTO_MODULE_DESCRIPTOR, name.c_str() ); goto error; } if (kurento_module == NULL) { goto error; } module_name = kurento_module->get_name(); if (modules.find (module_name) != modules.end() ) { GST_ERROR ("Module %s already loaded from another library not loading " "from %s", module_name.c_str(), name.c_str() ); goto error; } modules[module_name] = kurento_module; g_module_make_resident (module); GST_INFO ("Loading module %s from %s", module_name.c_str(), name.c_str() ); return true; error: g_module_close (module); return false; }
gboolean plugin_load_module(const gchar *module_name, GlobalConfig *cfg, CfgArgs *args) { GModule *mod; static GModule *main_module_handle; gboolean (*init_func)(GlobalConfig *cfg, CfgArgs *args); gchar *module_init_func; const gchar *mp; gboolean result; ModuleInfo *module_info; /* lookup in the main executable */ if (!main_module_handle) main_module_handle = g_module_open(NULL, 0); module_init_func = plugin_get_module_init_name(module_name); if (g_module_symbol(main_module_handle, module_init_func, (gpointer *) &init_func)) { /* already linked in, no need to load explicitly */ goto call_init; } /* try to load it from external .so */ if (cfg->lexer) mp = cfg_args_get(cfg->lexer->globals, "module-path"); else mp = NULL; if (!mp) mp = resolvedConfigurablePaths.initial_module_path; mod = plugin_dlopen_module(module_name, mp); if (!mod) { g_free(module_init_func); return FALSE; } g_module_make_resident(mod); module_info = plugin_get_module_info(mod); if (module_info->canonical_name) { g_free(module_init_func); module_init_func = plugin_get_module_init_name(module_info->canonical_name ? : module_name); }
static gboolean nautilus_module_load (GTypeModule *gmodule) { NautilusModule *module; module = NAUTILUS_MODULE (gmodule); module->library = g_module_open (module->path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); if (!module->library) { g_warning ("%s", g_module_error ()); return FALSE; } /* ORBit installs atexit() handlers, which would get unloaded together * with the module now that the main process doesn't depend on GConf anymore, * causing nautilus to sefgault at exit. * If we detect that an extension would pull in ORBit, we make the * module resident to prevent that. */ if (module_pulls_in_orbit (module->library)) { g_module_make_resident (module->library); } if (!g_module_symbol (module->library, "nautilus_module_initialize", (gpointer *)&module->initialize) || !g_module_symbol (module->library, "nautilus_module_shutdown", (gpointer *)&module->shutdown) || !g_module_symbol (module->library, "nautilus_module_list_types", (gpointer *)&module->list_types)) { g_warning ("%s", g_module_error ()); g_module_close (module->library); return FALSE; } module->initialize (gmodule); return TRUE; }
void plugin_init (Ekiga::KickStart& kickstart) { #if DEBUG std::cout << "Trying to load the ekiga test plugin... "; #endif gchar* filename = g_build_filename (g_get_tmp_dir (), "ekiga_test", NULL); GModule* plugin = g_module_open (filename, G_MODULE_BIND_LOCAL); g_free (filename); if (plugin != 0) { #if DEBUG std::cout << "loaded... "; #endif gpointer init_func = NULL; if (g_module_symbol (plugin, "ekiga_plugin_init", &init_func)) { #if DEBUG std::cout << "valid, running:" << std::endl; #endif g_module_make_resident (plugin); ((void (*)(Ekiga::KickStart&))init_func) (kickstart); } else { #if DEBUG std::cout << "invalid: " << g_module_error () << std::endl; #endif g_module_close (plugin); } } else { #if DEBUG std::cout << "failed to load the module" << std::endl; #endif } }
static GObject * _load_plugin_file (const gchar *file_path, const gchar *plugin_name, const gchar *plugin_type, GHashTable *config) { GObject *plugin = NULL; DBG("Loading plugin %s", file_path); GModule* plugin_module = g_module_open (file_path, G_MODULE_BIND_LAZY); if (plugin_module == NULL) { DBG("Plugin couldn't be opened: %s", g_module_error()); return NULL; } gchar* get_type_func = g_strdup_printf("tlm_%s_plugin_%s_get_type", plugin_type, plugin_name); gpointer p; DBG("Resolving symbol %s", get_type_func); gboolean symfound = g_module_symbol (plugin_module, get_type_func, &p); g_free(get_type_func); if (!symfound) { DBG("Symbol couldn't be resolved"); g_module_close (plugin_module); return NULL; } DBG("Creating plugin object"); GType (*plugin_get_type_f)(void) = p; plugin = g_object_new(plugin_get_type_f(), "config", config, NULL); if (plugin == NULL) { DBG("Plugin couldn't be created"); g_module_close (plugin_module); return NULL; } g_module_make_resident (plugin_module); return plugin; }
/** * TODO: Add error handling. A lot can go wrong here. */ ConboyPlugin* conboy_plugin_new_from_path (gchar *filename) { ConboyPlugin *result = NULL; typedef ConboyPlugin* (* TypeFunc) (void); TypeFunc func = NULL; g_printerr("INFO: Loading library: %s\n", filename); GModule *module = g_module_open(filename, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); if (module == NULL) { g_printerr("ERROR: Could not open library: %s\n", g_module_error()); } /* TODO: Why do we need this ???? */ g_module_make_resident(module); g_module_symbol(module, "conboy_plugin_new", (gpointer*)&func); if (func == NULL) { g_printerr("ERROR: Could not load plugin: %s\n", g_module_error()); return NULL; } result = func(); if (result == NULL) { g_printerr("ERROR: Cannot init plugin. Result is NULL.\n"); return NULL; } if (!CONBOY_IS_PLUGIN(result)) { g_printerr("ERROR: Connot init plugin. Result is not a plugin.\n"); return NULL; } result->gmodule = module; return result; }
static gboolean phidias_module_load (GTypeModule *gmodule) { PhidiasModule *module; PhidiasModuleRegisterFunc register_func; module = PHIDIAS_MODULE (gmodule); if (module->library == NULL) module->library = g_module_open (module->path, G_MODULE_BIND_LOCAL | G_MODULE_BIND_LAZY); if (module->library == NULL) { g_warning ("No library: %s", g_module_error ()); return FALSE; } if (!g_module_symbol (module->library, "register_module", (void *) ®ister_func)) { g_warning ("No symbol: %s", g_module_error ()); g_module_close (module->library); return FALSE; } if (!register_func) { g_warning ("Symbol 'register_module' is NULL."); g_module_close (module->library); return FALSE; } module->type = register_func (gmodule); if (module->type == 0) { g_warning ("Failed to register the GType(s)!"); g_module_close (module->library); return FALSE; } g_module_make_resident (module->library); return TRUE; }
static gboolean thunarx_provider_module_load (GTypeModule *type_module) { ThunarxProviderModule *module = THUNARX_PROVIDER_MODULE (type_module); gchar *path; /* load the module using the runtime link editor */ path = g_build_filename (THUNARX_DIRECTORY, type_module->name, NULL); module->library = g_module_open (path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); g_free (path); /* check if the load operation was successfull */ if (G_UNLIKELY (module->library == NULL)) { g_warning ("Failed to load plugin `%s': %s", type_module->name, g_module_error ()); return FALSE; } /* verify that all required public symbols are present in the plugin's symbol table */ if (!g_module_symbol (module->library, "thunar_extension_shutdown", (gpointer) &module->shutdown) || !g_module_symbol (module->library, "thunar_extension_initialize", (gpointer) &module->initialize) || !g_module_symbol (module->library, "thunar_extension_list_types", (gpointer) &module->list_types)) { g_warning ("Plugin `%s' lacks required symbols.", type_module->name); g_module_close (module->library); return FALSE; } /* initialize the plugin */ (*module->initialize) (module); /* ensure that the module will never be unloaded if it requests to be kept in memory */ if (G_UNLIKELY (module->resident)) g_module_make_resident (module->library); return TRUE; }
gboolean qof_load_backend_library (const char *directory, const char* module_name) { gchar *fullpath; GModule *backend; void (*module_init_func) (void); g_return_val_if_fail(g_module_supported(), FALSE); fullpath = g_module_build_path(directory, module_name); backend = g_module_open(fullpath, G_MODULE_BIND_LAZY); g_free(fullpath); if (!backend) { g_message ("%s: %s\n", PACKAGE, g_module_error ()); return FALSE; } if (g_module_symbol(backend, "qof_backend_module_init", (gpointer)&module_init_func)) module_init_func(); g_module_make_resident(backend); backend_module_list = g_slist_prepend( backend_module_list, backend ); return TRUE; }
/** Ensures that a plugin's module (*.so) will never be unloaded. * This is necessary if you register new GTypes in your plugin, e.g. when using own classes * using the GObject system. * * @param plugin Must be @ref geany_plugin. * * @since 0.16 */ void plugin_module_make_resident(GeanyPlugin *plugin) { g_return_if_fail(plugin); g_module_make_resident(plugin->priv->module); }
/** * gjs_import_native_module: * @context: * @module_obj: * @filename: filename or %NULL * @flags_p: * * Imports a native module by g_module_open a shared library. * If @filename is %NULL, do not dlopen, assume the library * is already loaded in the modules hash table */ JSBool gjs_import_native_module(JSContext *context, JSObject *module_obj, const char *filename, GjsNativeFlags *flags_p) { GModule *gmodule = NULL; GjsNativeModule *native_module; JSObject *parent; jsval tmp; if (flags_p) *flags_p = 0; if (filename != NULL) { /* Vital to load in global scope so any dependent libs * are loaded into the main app. We don't want a second * private copy of GTK or something. */ gmodule = g_module_open(filename, 0); if (gmodule == NULL) { gjs_throw(context, "Failed to load '%s': %s", filename, g_module_error()); return JS_FALSE; } } /* dlopen() as a side effect should have registered us as * a native module. We just have to reverse-engineer * the module id from module_obj. */ { char *module_name = get_module_name(context, module_obj, &tmp); native_module = lookup_native_module (context, module_get_parent(context, module_obj), module_name, TRUE); g_free(module_name); } if (!native_module) { if (gmodule) g_module_close(gmodule); return JS_FALSE; } if (flags_p) *flags_p = native_module->flags; if (gmodule) { /* make the module resident, which makes the close() a no-op * (basically we leak the module permanently) */ g_module_make_resident(gmodule); g_module_close(gmodule); } if (native_module->flags & GJS_NATIVE_SUPPLIES_MODULE_OBJ) { /* In this case we just throw away "module_obj" eventually, * since the native module defines itself in the parent of * module_obj directly. */ parent = module_get_parent(context, module_obj); return (* native_module->func) (context, parent); } else { return (* native_module->func) (context, module_obj); } }
static gboolean infinoted_plugin_dbus_initialize(InfinotedPluginManager* manager, gpointer plugin_info, GError** error) { InfinotedPluginDbus* plugin; gchar* gio_path; GModule* gio_module; plugin = (InfinotedPluginDbus*)plugin_info; /* Load the GIO dynamic library and make it resident. The reason for this * is that the infinoted executable does not link against gio, but this * module does. Therefore, when the module gets unloaded, libgio would be * unloaded as well. However, gio registers several types into global * gobject buffers such as the signal or property tables. After unloading, * those registrations would still be around, and some static strings would * even point to memory that is no longer available. This can lead to * seemingly random crashes when accessing some signals or properties of * intact objects/types, because gobject will scan its internal data * structures that also contain the invalidated strings. To avoid this * mess, we simply make sure that libgio stays around even after we are * unloaded. */ gio_path = g_module_build_path(NULL, "gio-2.0"); gio_module = g_module_open(gio_path, 0); g_free(gio_path); if(gio_module == NULL) { /* The error might be consumed after we have been dlclose()'d, so * use g_quark_from_string instead of g_quark_from_static_string. */ g_set_error( error, g_quark_from_string("INFINOTED_PLUGIN_DBUS_ERROR"), 0, "%s", g_module_error() ); return FALSE; } else { g_module_make_resident(gio_module); if(g_module_close(gio_module) != TRUE) { g_warning("Failed to close gio module: %s", g_module_error()); } } plugin->manager = manager; g_mutex_init(&plugin->mutex); g_mutex_lock(&plugin->mutex); /* We run the DBus activity in its own thread, so that we can iterate * a glib main loop there. */ plugin->thread = g_thread_try_new( "InfinotedPluginDbus", infinoted_plugin_dbus_thread_func, plugin_info, error ); g_mutex_unlock(&plugin->mutex); if(plugin->thread == NULL) { g_mutex_clear(&plugin->mutex); return FALSE; } return TRUE; }
static ModuleInfo * load_module (RuleInfo *info, gboolean initialize) { ModuleInfo *module_info = NULL; if (modules) { module_info = g_hash_table_lookup (modules, info->module_path); } if (!module_info) { GModule *module; /* Load the module */ module = g_module_open (info->module_path, G_MODULE_BIND_LOCAL); if (!module) { g_warning ("Could not load module '%s': %s", info->module_path, g_module_error ()); return NULL; } g_module_make_resident (module); module_info = g_slice_new0 (ModuleInfo); module_info->module = module; if (!g_module_symbol (module, EXTRACTOR_FUNCTION, (gpointer *) &module_info->extract_func)) { g_warning ("Could not load module '%s': Function %s() was not found, is it exported?", g_module_name (module), EXTRACTOR_FUNCTION); g_slice_free (ModuleInfo, module_info); return NULL; } g_module_symbol (module, INIT_FUNCTION, (gpointer *) &module_info->init_func); g_module_symbol (module, SHUTDOWN_FUNCTION, (gpointer *) &module_info->shutdown_func); /* Add it to the cache */ if (G_UNLIKELY (!modules)) { /* Key is an intern string, so * pointer comparison suffices */ modules = g_hash_table_new (NULL, NULL); } g_hash_table_insert (modules, (gpointer) info->module_path, module_info); } if (module_info && initialize && !module_info->initialized) { if (module_info->init_func) { GError *error = NULL; if (!(module_info->init_func) (&module_info->thread_awareness, &error)) { g_critical ("Could not initialize module %s: %s", g_module_name (module_info->module), (error) ? error->message : "No error given"); if (error) { g_error_free (error); } return NULL; } } else { module_info->thread_awareness = TRACKER_MODULE_MAIN_THREAD; } module_info->initialized = TRUE; } return module_info; }
GModule* g_module_open (const gchar *file_name, GModuleFlags flags) { GModule *module; gpointer handle = NULL; gchar *name = NULL; SUPPORT_OR_RETURN (NULL); g_static_rec_mutex_lock (&g_module_global_lock); if (G_UNLIKELY (!module_debug_initialized)) _g_module_debug_init (); if (module_debug_flags & G_MODULE_DEBUG_BIND_NOW_MODULES) flags &= ~G_MODULE_BIND_LAZY; if (!file_name) { if (!main_module) { handle = _g_module_self (); if (handle) { main_module = g_new (GModule, 1); main_module->file_name = NULL; #ifdef G_OS_WIN32 main_module->cp_file_name = NULL; #endif main_module->handle = handle; main_module->ref_count = 1; main_module->is_resident = TRUE; main_module->unload = NULL; main_module->next = NULL; } } else main_module->ref_count++; g_static_rec_mutex_unlock (&g_module_global_lock); return main_module; } /* we first search the module list by name */ module = g_module_find_by_name (file_name); if (module) { module->ref_count++; g_static_rec_mutex_unlock (&g_module_global_lock); return module; } /* check whether we have a readable file right away */ if (g_file_test (file_name, G_FILE_TEST_IS_REGULAR)) name = g_strdup (file_name); /* try completing file name with standard library suffix */ if (!name) { name = g_strconcat (file_name, "." G_MODULE_SUFFIX, NULL); if (!g_file_test (name, G_FILE_TEST_IS_REGULAR)) { g_free (name); name = NULL; } } /* try completing by appending libtool suffix */ if (!name) { name = g_strconcat (file_name, ".la", NULL); if (!g_file_test (name, G_FILE_TEST_IS_REGULAR)) { g_free (name); name = NULL; } } /* we can't access() the file, lets hope the platform backends finds * it via library paths */ if (!name) { gchar *dot = strrchr (file_name, '.'); gchar *slash = strrchr (file_name, G_DIR_SEPARATOR); /* make sure the name has a suffix */ if (!dot || dot < slash) name = g_strconcat (file_name, "." G_MODULE_SUFFIX, NULL); else name = g_strdup (file_name); } /* ok, try loading the module */ if (name) { /* if it's a libtool archive, figure library file to load */ if (str_check_suffix (name, ".la")) /* libtool archive? */ { gchar *real_name = parse_libtool_archive (name); /* real_name might be NULL, but then module error is already set */ if (real_name) { g_free (name); name = real_name; } } if (name) handle = _g_module_open (name, (flags & G_MODULE_BIND_LAZY) != 0, (flags & G_MODULE_BIND_LOCAL) != 0); } else { gchar *display_file_name = g_filename_display_name (file_name); g_module_set_error_unduped (g_strdup_printf ("unable to access file \"%s\"", display_file_name)); g_free (display_file_name); } g_free (name); if (handle) { gchar *saved_error; GModuleCheckInit check_init; const gchar *check_failed = NULL; /* search the module list by handle, since file names are not unique */ module = g_module_find_by_handle (handle); if (module) { _g_module_close (module->handle, TRUE); module->ref_count++; g_module_set_error (NULL); g_static_rec_mutex_unlock (&g_module_global_lock); return module; } saved_error = g_strdup (g_module_error ()); g_module_set_error (NULL); module = g_new (GModule, 1); module->file_name = g_strdup (file_name); #ifdef G_OS_WIN32 module->cp_file_name = g_locale_from_utf8 (file_name, -1, NULL, NULL, NULL); #endif module->handle = handle; module->ref_count = 1; module->is_resident = FALSE; module->unload = NULL; module->next = modules; modules = module; /* check initialization */ if (g_module_symbol (module, "g_module_check_init", (gpointer) &check_init) && check_init != NULL) check_failed = check_init (module); /* we don't call unload() if the initialization check failed. */ if (!check_failed) g_module_symbol (module, "g_module_unload", (gpointer) &module->unload); if (check_failed) { gchar *error; error = g_strconcat ("GModule (", file_name ? file_name : "NULL", ") initialization check failed: ", check_failed, NULL); g_module_close (module); module = NULL; g_module_set_error (error); g_free (error); } else g_module_set_error (saved_error); g_free (saved_error); } if (module != NULL && (module_debug_flags & G_MODULE_DEBUG_RESIDENT_MODULES)) g_module_make_resident (module); g_static_rec_mutex_unlock (&g_module_global_lock); return module; }
void nm_device_factory_manager_load_factories (NMDeviceFactoryManagerFactoryFunc callback, gpointer user_data) { NMDeviceFactory *factory; const GSList *iter; GError *error = NULL; char **path, **paths; g_return_if_fail (factories_by_link == NULL); g_return_if_fail (factories_by_setting == NULL); factories_by_link = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_object_unref); factories_by_setting = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref); /* Register internal factories first */ for (iter = internal_types; iter; iter = iter->next) { GType ftype = (GType) GPOINTER_TO_SIZE (iter->data); factory = (NMDeviceFactory *) g_object_new (ftype, NULL); g_assert (factory); _add_factory (factory, FALSE, "internal", callback, user_data); } paths = read_device_factory_paths (); if (!paths) return; for (path = paths; *path; path++) { GModule *plugin; NMDeviceFactoryCreateFunc create_func; const char *item; item = strrchr (*path, '/'); g_assert (item); plugin = g_module_open (*path, G_MODULE_BIND_LOCAL); if (!plugin) { nm_log_warn (LOGD_HW, "(%s): failed to load plugin: %s", item, g_module_error ()); continue; } if (!g_module_symbol (plugin, "nm_device_factory_create", (gpointer) &create_func)) { nm_log_warn (LOGD_HW, "(%s): failed to find device factory creator: %s", item, g_module_error ()); g_module_close (plugin); continue; } factory = create_func (&error); if (!factory) { nm_log_warn (LOGD_HW, "(%s): failed to initialize device factory: %s", item, NM_G_ERROR_MSG (error)); g_clear_error (&error); g_module_close (plugin); continue; } g_clear_error (&error); if (_add_factory (factory, TRUE, g_module_name (plugin), callback, user_data)) g_module_make_resident (plugin); else g_module_close (plugin); g_object_unref (factory); } g_strfreev (paths); }