Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/processone/ejabberd.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBadlop <badlop@process-one.net>2011-11-26 20:03:24 +0400
committerBadlop <badlop@process-one.net>2011-11-26 20:04:18 +0400
commitf7076f49b6bf006ffb1abe9cbd7595a4a6b0aa46 (patch)
treea6f65cc6a627d8069ba2e5cfac820ee4b64b83e4
parent5c40d38b699aa323c8be0a5881a874c16f075276 (diff)
Avoid a possible race condition
-rw-r--r--src/mod_ip_blacklist.erl23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/mod_ip_blacklist.erl b/src/mod_ip_blacklist.erl
index eac61a766..718a25b1e 100644
--- a/src/mod_ip_blacklist.erl
+++ b/src/mod_ip_blacklist.erl
@@ -33,6 +33,7 @@
%% API:
-export([start/2,
+ preinit/2,
init/1,
stop/1]).
-export([update_bl_c2s/0]).
@@ -49,14 +50,20 @@
-record(bl_c2s, {ip}).
%% Start once for all vhost
-start(Host, Opts) ->
- case whereis(?PROCNAME) of
- undefined ->
- ?DEBUG("Starting mod_ip_blacklist ~p ~p~n", [Host, Opts]),
- register(?PROCNAME,
- spawn(?MODULE, init, [#state{}]));
- _ ->
- ok
+start(_Host, _Opts) ->
+ Pid = spawn(?MODULE, preinit, [self(), #state{}]),
+ receive {ok, Pid, PreinitResult} ->
+ PreinitResult
+ end.
+
+preinit(Parent, State) ->
+ Pid = self(),
+ try register(?PROCNAME, Pid) of
+ true ->
+ Parent ! {ok, Pid, true},
+ init(State)
+ catch error:_ ->
+ Parent ! {ok, Pid, true}
end.
%% TODO: