25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

Fix error creating ETS table if enabled in several vhosts (EJAB-551). Unregister the command when stopping the module.

SVN Revision: 2188
This commit is contained in:
Badlop 2009-06-16 13:52:37 +00:00
parent 6af85aea18
commit 0864e8a24f

View File

@ -165,25 +165,38 @@ loop(Filename) ->
%%% BEHAVIOUR CALLBACKS %%% BEHAVIOUR CALLBACKS
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
%% TODO: Improve this module to allow each virtual host to have a different
%% options. See http://support.process-one.net/browse/EJAB-561
start(_Host, Opts) -> start(_Host, Opts) ->
ejabberd_ctl:register_commands([{"reopen-weblog", "reopen http fileserver log file"}], case ets:info(mod_http_fileserver, name) of
?MODULE, ctl_process), undefined ->
start2(_Host, Opts);
_ ->
ok
end.
start2(_Host, Opts) ->
case gen_mod:get_opt(docroot, Opts, undefined) of case gen_mod:get_opt(docroot, Opts, undefined) of
undefined -> undefined ->
{'EXIT', {missing_document_root, ?MODULE}}; {'EXIT', {missing_document_root, ?MODULE}};
DocRoot -> DocRoot ->
case filelib:is_dir(DocRoot) of case filelib:is_dir(DocRoot) of
true -> true ->
% XXX WARNING, using a single ets table name will %% XXX WARNING, using a single ets table name will
% not work with virtual hosts %% not work with virtual hosts
ets:new(mod_http_fileserver, [named_table, public]), ets:new(mod_http_fileserver, [named_table, public]),
ets:insert(mod_http_fileserver, [{docroot, DocRoot}]), ets:insert(mod_http_fileserver, [{docroot, DocRoot}]),
case gen_mod:get_opt(accesslog, Opts, undefined) of case gen_mod:get_opt(accesslog, Opts, undefined) of
undefined -> undefined ->
ok; ok;
Filename -> Filename ->
% XXX same remark as above for proc name %% XXX same remark as above for proc name
register(mod_http_fileserver_server, spawn(?MODULE, loop, [Filename])), ejabberd_ctl:register_commands(
[{"reopen-weblog",
"reopen http fileserver log file"}],
?MODULE, ctl_process),
register(mod_http_fileserver_server,
spawn(?MODULE, loop, [Filename])),
open_file(Filename) open_file(Filename)
end; end;
_Else -> _Else ->
@ -200,6 +213,10 @@ stop(_Host) ->
[] -> [] ->
ok; ok;
[{accessfile, AccessFile}] -> [{accessfile, AccessFile}] ->
ejabberd_ctl:unregister_commands(
[{"reopen-weblog",
"reopen http fileserver log file"}],
?MODULE, ctl_process),
mod_http_fileserver_server ! stop, mod_http_fileserver_server ! stop,
file:close(AccessFile) file:close(AccessFile)
end, end,