module_t *module_load(const char *Path, const char *File) { log_writef("Loading %s, path = %s.\n", File, Path); if (Path) return module_load_internal(Path, File, 0); //pthread_t Thread = pthread_self(); //printf("<thread @ %x> Entering module_load:%d(%s, %s)\n", Thread, __LINE__, Path, File); const char *Alias = path_join("library:", File); pthread_mutex_lock(LibRivaMutex); module_t *Module = stringtable_get(Modules, Alias); pthread_mutex_unlock(LibRivaMutex); if (Module) { module_reload(Module); //printf("Found module %s = 0x%x\n", Alias, Module); //printf("<thread @ %x> Leaving module_load:%d(%s, %s)\n", Thread, __LINE__, Path, File); return Module; }; for (path_node *Path = ModuleLibrary; Path; Path = Path->Next) { Module = module_load_internal(Path->Dir, File, Alias); if (Module) { //printf("<thread @ %x> Leaving module_load:%d(%s, %s)\n", Thread, __LINE__, Path, File); return Module; }; }; //printf("<thread @ %x> Leaving module_load:%d(%s, %s)\n", Thread, __LINE__, Path, File); return 0; };
static module_t *module_load_internal(const char *Path, const char *File, const char *Alias) { //pthread_t Thread = pthread_self(); //printf("<thread @ %x> Entering module_load_internal:%d(%s, %s)\n", Thread, __LINE__, Path, File); const char *Name = path_join(Path, File); pthread_mutex_lock(LibRivaMutex); module_t *Module = stringtable_get(Modules, Name); if (Module) { pthread_mutex_unlock(LibRivaMutex); module_reload(Module); //printf("<thread @ %x> Leaving module_load_internal:%d(%s, %s)\n", Thread, __LINE__, Path, File); return Module; }; module_provider_t *Providers = module_find_loaders(Name, ModuleLoaders, -1); if (!Providers) { pthread_mutex_unlock(LibRivaMutex); //printf("<thread @ %x> Leaving module_load_internal:%d(%s, %s)\n", Thread, __LINE__, Path, File); return 0; }; Module = stringtable_get(Modules, Name); if (Module) { pthread_mutex_unlock(LibRivaMutex); module_reload(Module); //printf("<thread @ %x> Leaving module_load_internal:%d(%s, %s)\n", pthread_self(), __LINE__, Path, File); return Module; }; Module = new(module_t); Module->Type = ModuleT; Module->Name = Name; Module->Path = path_dir(Name); Module->TimeStamp = ModuleTimeStamp; Module->Lock[0] = RecursiveMutex; stringtable_put(Modules, Name, Module); if (Alias) stringtable_put(Modules, Alias, Module); pthread_mutex_lock(Module->Lock); pthread_mutex_unlock(LibRivaMutex); module_call_loaders(Name, Module, Providers); pthread_mutex_unlock(Module->Lock); //printf("<thread @ %x> Leaving module_load_internal:%d(%s, %s)\n", Thread, __LINE__, Path, File); return Module; };
static void module_command(client c) { if (!strcasecmp(c->argv[1], "load")) { /* FIXME */ if (module_load("/var/lib/xcb", c->argv[2]) != MODULE_LOAD_SUCCESS) add_reply_error_format(c, "module '%s' loaded NOT OK", c->argv[2]); else add_reply_string_format(c, "module '%s' loaded OK\r\n", c->argv[2]); } else if (!strcasecmp(c->argv[1], "unload")) { if (module_unload(c->argv[2]) != MODULE_LOAD_SUCCESS) add_reply_error_format(c, "module '%s' unloaded NOT OK", c->argv[2]); else add_reply_string_format(c, "module '%s' unloaded OK\r\n", c->argv[2]); } else if (!strcasecmp(c->argv[1], "reload")) { if (module_reload(c->argv[2]) != MODULE_RELOAD_SUCCESS) add_reply_error_format(c, "module '%s' reloaded NOT OK", c->argv[2]); else add_reply_string_format(c, "module '%s' reloaded OK\r\n", c->argv[2]); } else add_reply_error_format(c, "unknown action '%s'", c->argv[1]); add_reply_string(c, "\r\n", 2); }