X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodmanager_dynamic.cpp;h=fa6b119a025234bd9b7feaade560663aebae3196;hb=4498f1abd163b140efcbbd9e75173665c9b1c29f;hp=156105ad8db041a6801efe430dbc2a05f3ac3522;hpb=704c793d479f835180e9d89d82cd21a2c6c6521d;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modmanager_dynamic.cpp b/src/modmanager_dynamic.cpp index 156105ad8..fa6b119a0 100644 --- a/src/modmanager_dynamic.cpp +++ b/src/modmanager_dynamic.cpp @@ -2,7 +2,7 @@ * | Inspire Internet Relay Chat Daemon | * +------------------------------------+ * - * InspIRCd: (C) 2002-2009 InspIRCd Development Team + * InspIRCd: (C) 2002-2010 InspIRCd Development Team * See: http://wiki.inspircd.org/Credits * * This program is free but copyrighted software; see @@ -44,6 +44,8 @@ bool ModuleManager::Load(const char* filename) dirent* entry = NULL; while (0 != (entry = readdir(library))) { + if (entry->d_name[0] == '.') + continue; if (InspIRCd::Match(entry->d_name, filename, ascii_case_insensitive_map)) { if (!this->Load(entry->d_name)) @@ -82,18 +84,18 @@ bool ModuleManager::Load(const char* filename) try { - newmod = newhandle->callInit(); + newmod = newhandle->CallInit(); if (newmod) { newmod->ModuleSourceFile = filename_str; newmod->ModuleDLLManager = newhandle; - Version v = newmod->GetVersion(); + Modules[filename_str] = newmod; + newmod->init(); + Version v = newmod->GetVersion(); ServerInstance->Logs->Log("MODULE", DEFAULT,"New module introduced: %s (Module version %s)%s", - filename, v.version.c_str(), (!(v.Flags & VF_VENDOR) ? " [3rd Party]" : " [Vendor]")); - - Modules[filename_str] = newmod; + filename, newhandle->GetVersion().c_str(), (!(v.Flags & VF_VENDOR) ? " [3rd Party]" : " [Vendor]")); } else { @@ -106,8 +108,10 @@ bool ModuleManager::Load(const char* filename) catch (CoreException& modexcept) { // failure in module constructor - delete newmod; - delete newhandle; + if (newmod) + DoSafeUnload(newmod); + else + delete newhandle; LastModuleError = "Unable to load " + filename_str + ": " + modexcept.GetReason(); ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError); return false; @@ -136,78 +140,6 @@ bool ModuleManager::Load(const char* filename) return true; } -bool ModuleManager::CanUnload(Module* mod) -{ - std::map::iterator modfind = Modules.find(mod->ModuleSourceFile); - - if (modfind == Modules.end() || modfind->second != mod) - { - LastModuleError = "Module " + mod->ModuleSourceFile + " is not loaded, cannot unload it!"; - ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError); - return false; - } - if (mod->GetVersion().Flags & VF_STATIC) - { - LastModuleError = "Module " + mod->ModuleSourceFile + " not unloadable (marked static)"; - ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError); - return false; - } - std::pair intercount = GetInterfaceInstanceCount(mod); - if (intercount.first > 0) - { - LastModuleError = "Failed to unload module " + mod->ModuleSourceFile + ", being used by " + ConvToStr(intercount.first) + " other(s) via interface '" + intercount.second + "'"; - ServerInstance->Logs->Log("MODULE", DEFAULT, LastModuleError); - return false; - } - return true; -} - -void ModuleManager::DoSafeUnload(Module* mod) -{ - std::map::iterator modfind = Modules.find(mod->ModuleSourceFile); - - std::vector > items; - ServerInstance->Extensions.BeginUnregister(modfind->second, items); - /* Give the module a chance to tidy out all its metadata */ - for (chan_hash::iterator c = ServerInstance->chanlist->begin(); c != ServerInstance->chanlist->end(); c++) - { - mod->OnCleanup(TYPE_CHANNEL,c->second); - c->second->doUnhookExtensions(items); - const UserMembList* users = c->second->GetUsers(); - for(UserMembCIter mi = users->begin(); mi != users->end(); mi++) - mi->second->doUnhookExtensions(items); - } - for (user_hash::iterator u = ServerInstance->Users->clientlist->begin(); u != ServerInstance->Users->clientlist->end(); u++) - { - mod->OnCleanup(TYPE_USER,u->second); - u->second->doUnhookExtensions(items); - } - for(char m='A'; m <= 'z'; m++) - { - ModeHandler* mh; - mh = ServerInstance->Modes->FindMode(m, MODETYPE_USER); - if (mh && mh->creator == mod) - ServerInstance->Modes->DelMode(mh); - mh = ServerInstance->Modes->FindMode(m, MODETYPE_CHANNEL); - if (mh && mh->creator == mod) - ServerInstance->Modes->DelMode(mh); - } - - /* Tidy up any dangling resolvers */ - ServerInstance->Res->CleanResolvers(mod); - - FOREACH_MOD(I_OnUnloadModule,OnUnloadModule(mod)); - - DetachAll(mod); - - Modules.erase(modfind); - ServerInstance->GlobalCulls.AddItem(mod); - - ServerInstance->Logs->Log("MODULE", DEFAULT,"Module %s unloaded",mod->ModuleSourceFile.c_str()); - this->ModCount--; - ServerInstance->BuildISupport(); -} - namespace { struct UnloadAction : public HandlerBase0 { @@ -237,7 +169,8 @@ namespace { ServerInstance->GlobalCulls.Apply(); delete dll; bool rv = ServerInstance->Modules->Load(name.c_str()); - callback->Call(rv); + if (callback) + callback->Call(rv); ServerInstance->GlobalCulls.AddItem(this); } };