aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2012-05-19 20:46:44 +0100
committerMatthew Wild <mwild1@gmail.com>2012-05-19 20:46:44 +0100
commit6faa60a8dc15eb061204ee6921296c2851ec0f3c (patch)
treeca52555ee223d67d86f5e4a2555a14627eaba907
parent68907c01f2ccd08936abbfac4386556cf94f66b5 (diff)
downloadprosody-6faa60a8dc15eb061204ee6921296c2851ec0f3c.tar.gz
prosody-6faa60a8dc15eb061204ee6921296c2851ec0f3c.zip
portmanager: Fix to deactivate services when they are unregistered (metatable:iter() wins)
-rw-r--r--core/portmanager.lua21
1 files changed, 8 insertions, 13 deletions
diff --git a/core/portmanager.lua b/core/portmanager.lua
index a6e8b38f..420c59ff 100644
--- a/core/portmanager.lua
+++ b/core/portmanager.lua
@@ -134,15 +134,11 @@ function activate(service_name)
return true;
end
-function deactivate(service_name)
- local active = active_services:search(service_name)[1];
- if not active then return; end
- for interface, ports in pairs(active) do
- for port, active_service in pairs(ports) do
- close(interface, port);
- end
+function deactivate(service_name, service_info)
+ for name, interface, port, active_service in active_services:iter(service_name, nil, nil, service_info) do
+ close(interface, port);
end
- log("info", "Deactivated service '%s'", service_name);
+ log("info", "Deactivated service '%s'", service_name or service_info.name);
end
function register_service(service_name, service_info)
@@ -161,17 +157,16 @@ function register_service(service_name, service_info)
end
function unregister_service(service_name, service_info)
+ log("debug", "Unregistering service: %s", service_name);
local service_info_list = services[service_name];
for i, service in ipairs(service_info_list) do
if service == service_info then
table.remove(service_info_list, i);
end
end
- if active_services[service_name] == service_info then
- deactivate(service_name);
- if #service_info_list > 0 then -- Other services registered with this name
- activate(service_name); -- Re-activate with the next available one
- end
+ deactivate(nil, service_info);
+ if #service_info_list > 0 then -- Other services registered with this name
+ activate(service_name); -- Re-activate with the next available one
end
fire_event("service-removed", { name = service_name, service = service_info });
end