From 283563287be02e32ef8a4cad526855faf327f24e Mon Sep 17 00:00:00 2001 From: danieldg Date: Tue, 11 Aug 2009 20:41:04 +0000 Subject: Fix module prioritization when a module asks to be after spanningtree, which asks to be last git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11502 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/modules.cpp b/src/modules.cpp index 87e2de705..66134e3bc 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -288,11 +288,16 @@ bool ModuleManager::SetPriority(Module* mod, Implementation i, Priority s, Modul break; /* Module wants to be first, sod everything else */ case PRIORITY_FIRST: - swap_pos = 0; + if (prioritizationState != PRIO_STATE_FIRST) + swap = false; + else + swap_pos = 0; break; - /* Module is submissive and wants to be last... awww. */ + /* Module wants to be last. */ case PRIORITY_LAST: - if (EventHandlers[i].empty()) + if (prioritizationState != PRIO_STATE_FIRST) + swap = false; + else if (EventHandlers[i].empty()) swap_pos = 0; else swap_pos = EventHandlers[i].size() - 1; @@ -339,6 +344,9 @@ bool ModuleManager::SetPriority(Module* mod, Implementation i, Priority s, Modul /* Do we need to swap? */ if (swap && (swap_pos != source)) { + // We are going to change positions; we'll need to run again to verify all requirements + if (prioritizationState == PRIO_STATE_LAST) + prioritizationState = PRIO_STATE_AGAIN; /* Suggestion from Phoenix, "shuffle" the modules to better retain call order */ int incrmnt = 1; @@ -492,8 +500,17 @@ bool ModuleManager::Load(const char* filename) * not just the one thats loading, as the new module could affect the preference * of others */ - for (std::map >::iterator n = Modules.begin(); n != Modules.end(); ++n) - n->second.second->Prioritize(); + for(int tries = 0; tries < 20; tries++) + { + prioritizationState = tries > 0 ? PRIO_STATE_LAST : PRIO_STATE_FIRST; + for (std::map >::iterator n = Modules.begin(); n != Modules.end(); ++n) + n->second.second->Prioritize(); + + if (prioritizationState == PRIO_STATE_LAST) + break; + if (tries == 19) + Instance->Logs->Log("MODULE", DEFAULT, "Hook priority dependency loop detected while loading " + filename_str); + } Instance->BuildISupport(); return true; -- cgit v1.2.3