Mercurial > prosody-hg
view loader.lua @ 14113:b9688ac25255 13.0
mod_admin_shell: Improve per-host command cleanup
In some cases, host command handlers were not being cleaned up after the
source module was unloaded, for example. This is because mod_admin_shell saw
that the handler being removed did not match the installed handler. But this
is expected for the new per-host commands, because the installed handler is a
wrapper function which routes between the hosts.
The wrapper function itself also held a reference via upvalue to the first
command object which added it, just so it could read the argument names and
such. This could cause command objects, and anything referenced by the
handler, to stay around in memory longer than expected, even after a module
has been unloaded or a host deactivated.
The new logic breaks out the handler function to eliminate any unexpected
upvalues. It improves the cleanup logic when a command is removed. Finally,
it also cleans up commands when mod_admin_shell itself is unloaded.
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Fri, 27 Mar 2026 12:43:10 +0000 |
| parents | ef586363d90f |
| children | 76ece4dd9782 |
line wrap: on
line source
-- Allow for both require"util.foo" and require"prosody.util.foo" for a -- transition period while we update all require calls. if (...) == "prosody.loader" then -- For require"util.foo" also look in paths equivalent to "prosody.util.foo" package.path = package.path:gsub("([^;]*)(?[^;]*)", "%1prosody/%2;%1%2"); package.cpath = package.cpath:gsub("([^;]*)(?[^;]*)", "%1prosody/%2;%1%2"); else -- When requiring "prosody.x", also look for "x" for i = #package.searchers, 1, -1 do local search = package.searchers[i]; table.insert(package.searchers, i, function(module_name) local lib = module_name:match("^prosody%.(.*)$"); if lib then return search(lib); end end) end end -- Look for already loaded module with or without prefix setmetatable(package.loaded, { __index = function(loaded, module_name) local suffix = module_name:match("^prosody%.(.*)$"); if suffix then return rawget(loaded, suffix); end local prefixed = rawget(loaded, "prosody." .. module_name); if prefixed ~= nil then return prefixed; end end; })
