From f3bf402e7a6538a492dc1ef24f68548bd89a7c6d Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Mon, 14 Sep 2015 00:49:31 +0200 Subject: [PATCH] mod_http_upload: Stop correct process name Make sure the stop/1 function uses the same process name as the start/2 function. --- mod_http_upload/src/mod_http_upload.erl | 36 ++++++++++++++----------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/mod_http_upload/src/mod_http_upload.erl b/mod_http_upload/src/mod_http_upload.erl index 7e216e0..afc4a72 100644 --- a/mod_http_upload/src/mod_http_upload.erl +++ b/mod_http_upload/src/mod_http_upload.erl @@ -94,11 +94,10 @@ %% gen_mod/supervisor callbacks. %%-------------------------------------------------------------------- --spec start_link(binary(), binary(), gen_mod:opts()) +-spec start_link(binary(), atom(), gen_mod:opts()) -> {ok, pid()} | ignore | {error, _}. -start_link(ServerHost, ProcHost, Opts) -> - Proc = gen_mod:get_module_proc(ProcHost, ?PROCNAME), +start_link(ServerHost, Proc, Opts) -> ?GEN_SERVER:start_link({local, Proc}, ?MODULE, {ServerHost, Opts}, []). -spec start(binary(), gen_mod:opts()) -> {ok, _} | {ok, _, _} | {error, _}. @@ -114,18 +113,9 @@ start(ServerHost, Opts) -> remove_user, 50); false -> ok end, - PutURL = gen_mod:get_opt(put_url, Opts, - fun(<<"http://", _/binary>> = URL) -> URL; - (<<"https://", _/binary>> = URL) -> URL; - (_) -> <<"http://@HOST@">> - end, - <<"http://@HOST@">>), - [_, ProcHost | _] = binary:split(expand_host(PutURL, ServerHost), - [<<"http://">>, <<"https://">>, - <<":">>, <<"/">>], [global]), - Proc = gen_mod:get_module_proc(ProcHost, ?PROCNAME), + Proc = get_proc_name(ServerHost), Spec = {Proc, - {?MODULE, start_link, [ServerHost, ProcHost, Opts]}, + {?MODULE, start_link, [ServerHost, Proc, Opts]}, permanent, 3000, worker, @@ -145,7 +135,7 @@ stop(ServerHost) -> remove_user, 50); false -> ok end, - Proc = gen_mod:get_module_proc(ServerHost, ?PROCNAME), + Proc = get_proc_name(ServerHost), ok = supervisor:terminate_child(ejabberd_sup, Proc), ok = supervisor:delete_child(ejabberd_sup, Proc). @@ -741,6 +731,22 @@ code_to_message(405) -> <<"Method not allowed.">>; code_to_message(413) -> <<"File size doesn't match requested size.">>; code_to_message(500) -> <<"Internal server error.">>. +%% Miscellaneous helpers. + +-spec get_proc_name(binary()) -> atom(). + +get_proc_name(ServerHost) -> + PutURL = gen_mod:get_module_opt(ServerHost, ?MODULE, put_url, + fun(<<"http://", _/binary>> = URL) -> URL; + (<<"https://", _/binary>> = URL) -> URL; + (_) -> <<"http://@HOST@">> + end, + <<"http://@HOST@">>), + [_, ProcHost | _] = binary:split(expand_host(PutURL, ServerHost), + [<<"http://">>, <<"https://">>, + <<":">>, <<"/">>], [global]), + gen_mod:get_module_proc(ProcHost, ?PROCNAME). + %%-------------------------------------------------------------------- %% Remove user. %%--------------------------------------------------------------------