From c2dface515cc0b5dc2a0f28c1a4ce18cc797f7c9 Mon Sep 17 00:00:00 2001 From: Badlop Date: Wed, 17 Nov 2010 20:29:36 +0100 Subject: [PATCH] Fix http-bind supervisor to support multiple vhosts (EJAB-1321) --- src/web/ejabberd_http_bind.erl | 8 ++++++- src/web/mod_http_bind.erl | 40 ++++++++++------------------------ 2 files changed, 19 insertions(+), 29 deletions(-) diff --git a/src/web/ejabberd_http_bind.erl b/src/web/ejabberd_http_bind.erl index ffbe1fe13..37fa90d99 100644 --- a/src/web/ejabberd_http_bind.erl +++ b/src/web/ejabberd_http_bind.erl @@ -110,6 +110,8 @@ -define(PROCESS_DELAY_MIN, 0). -define(PROCESS_DELAY_MAX, 1000). +%% Line copied from mod_http_bind.erl +-define(PROCNAME_MHB, ejabberd_mod_http_bind). %%%---------------------------------------------------------------------- %%% API @@ -118,7 +120,8 @@ %% supervisor start(XMPPDomain, Sid, Key, IP) -> ?DEBUG("Starting session", []), - case catch supervisor:start_child(ejabberd_http_bind_sup, [Sid, Key, IP]) of + SupervisorProc = gen_mod:get_module_proc(XMPPDomain, ?PROCNAME_MHB), + case catch supervisor:start_child(SupervisorProc, [Sid, Key, IP]) of {ok, Pid} -> {ok, Pid}; {error, _} = Err -> @@ -129,6 +132,9 @@ start(XMPPDomain, Sid, Key, IP) -> ?ERROR_MSG("Cannot start HTTP bind session: ~p", [Err]), Err end; + {'EXIT', {noproc, _}} = Exit -> + ?DEBUG("Cannot start HTTP bind session because mod_http_bind seems stopped:~n~p", [Exit]), + {error, Exit}; Exit -> ?ERROR_MSG("Cannot start HTTP bind session: ~p", [Exit]), {error, Exit} diff --git a/src/web/mod_http_bind.erl b/src/web/mod_http_bind.erl index a8b47019c..aa4f1dedf 100644 --- a/src/web/mod_http_bind.erl +++ b/src/web/mod_http_bind.erl @@ -49,6 +49,8 @@ -include("ejabberd_http.hrl"). -include("http_bind.hrl"). +-define(PROCNAME_MHB, ejabberd_mod_http_bind). + %% Duplicated from ejabberd_http_bind. %% TODO: move to hrl file. -record(http_bind, {id, pid, to, hold, wait, process_delay, version}). @@ -101,41 +103,23 @@ get_human_html_xmlel() -> %%%---------------------------------------------------------------------- %%% BEHAVIOUR CALLBACKS %%%---------------------------------------------------------------------- -start(_Host, _Opts) -> +start(Host, _Opts) -> setup_database(), - HTTPBindSupervisor = - {ejabberd_http_bind_sup, + Proc = gen_mod:get_module_proc(Host, ?PROCNAME_MHB), + ChildSpec = + {Proc, {ejabberd_tmp_sup, start_link, - [ejabberd_http_bind_sup, ejabberd_http_bind]}, + [Proc, ejabberd_http_bind]}, permanent, infinity, supervisor, [ejabberd_tmp_sup]}, - case supervisor:start_child(ejabberd_sup, HTTPBindSupervisor) of - {ok, _Pid} -> - ok; - {ok, _Pid, _Info} -> - ok; - {error, {already_started, _PidOther}} -> - % mod_http_bind is already started so it will not be started again - ok; - {error, Error} -> - exit({start_child_error, Error}) - end. + supervisor:start_child(ejabberd_sup, ChildSpec). -stop(_Host) -> - case supervisor:terminate_child(ejabberd_sup, ejabberd_http_bind_sup) of - ok -> - ok; - {error, Error} -> - exit({terminate_child_error, Error}) - end, - case supervisor:delete_child(ejabberd_sup, ejabberd_http_bind_sup) of - ok -> - ok; - {error, Error2} -> - exit({delete_child_error, Error2}) - end. +stop(Host) -> + Proc = gen_mod:get_module_proc(Host, ?PROCNAME_MHB), + supervisor:terminate_child(ejabberd_sup, Proc), + supervisor:delete_child(ejabberd_sup, Proc). setup_database() -> migrate_database(),