mirror of
https://github.com/processone/ejabberd.git
synced 2024-06-14 22:00:16 +02:00
Avoid starting several time the owner process
This commit is contained in:
parent
9ff7257287
commit
e5fd1ee4f6
15
src/jid.erl
15
src/jid.erl
|
@ -50,7 +50,7 @@
|
||||||
-spec start() -> ok.
|
-spec start() -> ok.
|
||||||
|
|
||||||
start() ->
|
start() ->
|
||||||
Owner = spawn(fun() -> ets_keepalive() end),
|
{ok, Owner} = ets_owner(),
|
||||||
SplitPattern = binary:compile_pattern([<<"@">>, <<"/">>]),
|
SplitPattern = binary:compile_pattern([<<"@">>, <<"/">>]),
|
||||||
%% Table is public to allow ETS insert to fix / update the table even if table already exist
|
%% Table is public to allow ETS insert to fix / update the table even if table already exist
|
||||||
%% with another owner.
|
%% with another owner.
|
||||||
|
@ -58,6 +58,19 @@ start() ->
|
||||||
ets:insert(jlib, {string_to_jid_pattern, SplitPattern}),
|
ets:insert(jlib, {string_to_jid_pattern, SplitPattern}),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
ets_owner() ->
|
||||||
|
case whereis(jlib_ets) of
|
||||||
|
undefined ->
|
||||||
|
Pid = spawn(fun() -> ets_keepalive() end),
|
||||||
|
case catch register(jlib_ets, Pid) of
|
||||||
|
true ->
|
||||||
|
{ok, Pid};
|
||||||
|
Error -> Error
|
||||||
|
end;
|
||||||
|
Pid ->
|
||||||
|
{ok,Pid}
|
||||||
|
end.
|
||||||
|
|
||||||
%% Process used to keep jlib ETS table alive in case the original owner dies.
|
%% Process used to keep jlib ETS table alive in case the original owner dies.
|
||||||
%% The table need to be public, otherwise subsequent inserts would fail.
|
%% The table need to be public, otherwise subsequent inserts would fail.
|
||||||
ets_keepalive() ->
|
ets_keepalive() ->
|
||||||
|
|
Loading…
Reference in New Issue
Block a user