summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBadlop <badlop@process-one.net>2011-04-11 21:27:19 +0200
committerBadlop <badlop@process-one.net>2011-04-11 21:27:19 +0200
commit05e3893f60b82da54d001782cd3d7eec6b0612f1 (patch)
tree1ef45bb062483924caf65b48807c14f1eb4de031 /src
parentSupport more captcha_host value formats (EJAB-1418) (diff)
If extauth script crashes, ejabberd should restart it (EJAB-1428)
Diffstat (limited to 'src')
-rw-r--r--src/extauth.erl16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/extauth.erl b/src/extauth.erl
index 3b2e7db6..f4939298 100644
--- a/src/extauth.erl
+++ b/src/extauth.erl
@@ -45,11 +45,18 @@
start(Host, ExtPrg) ->
lists:foreach(
fun(This) ->
- spawn(?MODULE, init, [get_process_name(Host, This), ExtPrg])
+ start_instance(get_process_name(Host, This), ExtPrg)
end,
lists:seq(0, get_instances(Host)-1)
).
+start_instance(ProcessName, ExtPrg) ->
+ spawn(?MODULE, init, [ProcessName, ExtPrg]).
+
+restart_instance(ProcessName, ExtPrg) ->
+ unregister(ProcessName),
+ start_instance(ProcessName, ExtPrg).
+
init(ProcessName, ExtPrg) ->
register(ProcessName, self()),
process_flag(trap_exit,true),
@@ -125,8 +132,7 @@ loop(Port, Timeout, ProcessName, ExtPrg) ->
Timeout ->
?ERROR_MSG("extauth call '~p' didn't receive response", [Msg]),
Caller ! {eauth, false},
- unregister(ProcessName),
- Pid = spawn(?MODULE, init, [ProcessName, ExtPrg]),
+ Pid = restart_instance(ProcessName, ExtPrg),
flush_buffer_and_forward_messages(Pid),
exit(port_terminated)
end;
@@ -137,7 +143,9 @@ loop(Port, Timeout, ProcessName, ExtPrg) ->
exit(normal)
end;
{'EXIT', Port, Reason} ->
- ?CRITICAL_MSG("~p ~n", [Reason]),
+ ?CRITICAL_MSG("extauth script has exitted abruptly with reason '~p'", [Reason]),
+ Pid = restart_instance(ProcessName, ExtPrg),
+ flush_buffer_and_forward_messages(Pid),
exit(port_terminated)
end.