From 9f4f2817d17deacbe7d8e99d31471e8e4e0f868a Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Sat, 16 Mar 2013 23:35:19 +0700 Subject: [PATCH] Fix #293 In GetAvailableMods() modules paths were returned like "moddir//module.pm", but when they are loaded, they use path "moddir/module.pm". Because of that our hack of cleaning %INC when the module is unloaded, which enables UpdateMod, removed wrong record from %INC, left right record in it, and erased the module's namespace. When the module was loaded again, the namespace was not restored, because "require" didn't load the module, because it was still in %INC. So, when we call a function of that module, the function does not exist anymore. --- include/znc/FileUtils.h | 2 +- modules/modperl.cpp | 4 +++- modules/modperl/startup.pl | 5 +++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/znc/FileUtils.h b/include/znc/FileUtils.h index f8d37880..e2be4e9a 100644 --- a/include/znc/FileUtils.h +++ b/include/znc/FileUtils.h @@ -187,7 +187,7 @@ public: continue; } - CFile *file = new CFile(sDir + "/" + de->d_name/*, this*/); // @todo need to pass pointer to 'this' if we want to do Sort() + CFile *file = new CFile(sDir.TrimSuffix_n("/") + "/" + de->d_name/*, this*/); // @todo need to pass pointer to 'this' if we want to do Sort() push_back(file); } diff --git a/modules/modperl.cpp b/modules/modperl.cpp index e305063a..56977ecc 100644 --- a/modules/modperl.cpp +++ b/modules/modperl.cpp @@ -211,7 +211,9 @@ public: PUSH_STR(sName); PUSH_PTR(CModInfo*, &ModInfo); PCALL("ZNC::Core::ModInfoByPath"); - if (!SvTRUE(ERRSV)) { + if (SvTRUE(ERRSV)) { + DEBUG(__PRETTY_FUNCTION__ << ": " << sPath << ": " << PString(ERRSV)); + } else if (ModInfo.SupportsType(eType)) { ssMods.insert(ModInfo); } PEND; diff --git a/modules/modperl/startup.pl b/modules/modperl/startup.pl index f357a421..52bbf67f 100644 --- a/modules/modperl/startup.pl +++ b/modules/modperl/startup.pl @@ -162,6 +162,11 @@ sub ModInfoByPath { $modinfo->SetName($modname); $modinfo->SetPath($modpath); $modinfo->AddType($_) for @types; + unless ($modrefcount{$modname}) { + say "Unloading $modpath from perl, because it's not loaded as a module"; + ZNC::_CleanupStash($modname); + delete $INC{$modpath}; + } } sub CallModFunc {