From 8c0cc95a55b916e59daee1b0bf38d4600fcf9103 Mon Sep 17 00:00:00 2001 From: Badlop Date: Mon, 4 Jan 2010 20:32:44 +0000 Subject: [PATCH] When ejabberd stops, send stream close to clients (thanks to Alexey Shchepin)(EJAB-1112) SVN Revision: 2859 --- src/ejabberd_app.erl | 9 +++++++++ src/ejabberd_c2s.erl | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/ejabberd_app.erl b/src/ejabberd_app.erl index 2942ef076..d72702e07 100644 --- a/src/ejabberd_app.erl +++ b/src/ejabberd_app.erl @@ -77,6 +77,8 @@ start(_, _) -> prep_stop(State) -> stop_modules(), ejabberd_admin:stop(), + broadcast_c2s_shutdown(), + timer:sleep(5000), State. %% All the processes were killed when this function is called @@ -186,6 +188,13 @@ add_windows_nameservers() -> lists:foreach(fun(IPT) -> inet_db:add_ns(IPT) end, IPTs). +broadcast_c2s_shutdown() -> + Children = supervisor:which_children(ejabberd_c2s_sup), + lists:foreach( + fun({_, C2SPid, _, _}) -> + C2SPid ! system_shutdown + end, Children). + %%% %%% PID file %%% diff --git a/src/ejabberd_c2s.erl b/src/ejabberd_c2s.erl index 2346eb015..393e3795c 100644 --- a/src/ejabberd_c2s.erl +++ b/src/ejabberd_c2s.erl @@ -1258,6 +1258,19 @@ handle_info({route, From, To, Packet}, StateName, StateData) -> handle_info({'DOWN', Monitor, _Type, _Object, _Info}, _StateName, StateData) when Monitor == StateData#state.socket_monitor -> {stop, normal, StateData}; +handle_info(system_shutdown, StateName, StateData) -> + case StateName of + wait_for_stream -> + send_header(StateData#state.streamid, ?MYNAME, "1.0", ""), + send_element(StateData, exmpp_stream:error('system-shutdown')), + send_text(StateData, ?STREAM_TRAILER), + ok; + _ -> + send_element(StateData, exmpp_stream:error('system-shutdown')), + send_text(StateData, ?STREAM_TRAILER), + ok + end, + {stop, normal, StateData}; handle_info(Info, StateName, StateData) -> ?ERROR_MSG("Unexpected info: ~p", [Info]), fsm_next_state(StateName, StateData).