From e62ec2dc82da0d4e08ef2d2bc4c1416ddc573562 Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Mon, 21 Mar 2011 11:17:27 +0600 Subject: [PATCH] Remove bogus "Unable to find module" from modperl. When a module tries to being loaded, modperl looks for module.pm file. If there's no such file, it said "unable to find", which is bad in case when it's non-perl module. Loader of C++ modules clears sRetMsg string, so the message wasn't seen before (except debug and ZNC startup). But modpython does nothing with it (if python module doesn't set it itself), so in result we get stuff like "Loaded module [xxx] [Unable to find module [xxx]] [/home/user/.znc/modules/xxx.py]" which is pretty confusing. So now if perl version of the module isn't found, we just pass control to next available module loader without any error messages. Thanks to macmaN for reporting this. --- modules/modperl.cpp | 60 ++++++++++++++++++-------------------- modules/modperl/startup.pl | 4 +-- 2 files changed, 30 insertions(+), 34 deletions(-) diff --git a/modules/modperl.cpp b/modules/modperl.cpp index 4a37ae54..a7bbd579 100644 --- a/modules/modperl.cpp +++ b/modules/modperl.cpp @@ -73,44 +73,40 @@ public: return true; } - ELoadPerlMod LoadPerlModule(const CString& sModule, const CString& sArgs, CUser* pUser, CString& sRetMsg) { - ELoadPerlMod result = Perl_LoadError; - PSTART; - PUSH_STR(sModule); - PUSH_STR(sArgs); - PUSH_PTR(CUser*, pUser); - PCALL("ZNC::Core::LoadModule"); - - if (SvTRUE(ERRSV)) { - sRetMsg = PString(ERRSV); - } else if (2 == ret) { - result = static_cast(SvUV(ST(0))); - sRetMsg = PString(ST(1)); - } - DEBUG(__PRETTY_FUNCTION__ << " " << sRetMsg); - - PEND; - return result; - } - virtual EModRet OnModuleLoading(const CString& sModName, const CString& sArgs, bool& bSuccess, CString& sRetMsg) { if (!GetUser()) { return CONTINUE; } - switch (LoadPerlModule(sModName, sArgs, GetUser(), sRetMsg)) { - case Perl_NotFound: - return CONTINUE; - case Perl_Loaded: - bSuccess = true; - return HALT; - case Perl_LoadError: - bSuccess = false; - return HALT; + EModRet result = HALT; + PSTART; + PUSH_STR(sModName); + PUSH_STR(sArgs); + PUSH_PTR(CUser*, GetUser()); + PCALL("ZNC::Core::LoadModule"); + + if (SvTRUE(ERRSV)) { + sRetMsg = PString(ERRSV); + bSuccess = false; + result = HALT; + DEBUG("Perl ZNC::Core::LoadModule died: " << sRetMsg); + } else if (ret < 1 || 2 < ret) { + sRetMsg = "Error: Perl ZNC::Core::LoadModule returned " + CString(ret) + " values."; + bSuccess = false; + result = HALT; + } else { + ELoadPerlMod eLPM = static_cast(SvUV(ST(0))); + if (Perl_NotFound == eLPM) { + result = CONTINUE; // Not a Perl module + } else { + sRetMsg = PString(ST(1)); + result = HALT; + bSuccess = eLPM == Perl_Loaded; + } } - sRetMsg = "Something weird happened"; - bSuccess = false; - return HALT; + + PEND; + return result; } virtual EModRet OnModuleUnloading(CModule* pModule, bool& bSuccess, CString& sRetMsg) { diff --git a/modules/modperl/startup.pl b/modules/modperl/startup.pl index 67240f20..ddaa3818 100644 --- a/modules/modperl/startup.pl +++ b/modules/modperl/startup.pl @@ -94,9 +94,9 @@ sub LoadModule { return ($ZNC::Perl_LoadError, "Module [$modname] already loaded.") if defined $user->GetModules->FindModule($modname); my $modpath = ZNC::String->new; my $datapath = ZNC::String->new; - ZNC::CModules::FindModPath("$modname.pm", $modpath, $datapath) or return ($ZNC::Perl_NotFound, "Unable to find module [$modname]"); + ZNC::CModules::FindModPath("$modname.pm", $modpath, $datapath) or return ($ZNC::Perl_NotFound); $modpath = $modpath->GetPerlStr; - return ($ZNC::Perl_LoadError, "Incorrect perl module.") unless IsModule $modpath, $modname; + return ($ZNC::Perl_LoadError, "Incorrect perl module [$modpath]") unless IsModule $modpath, $modname; eval { require $modpath; };