summaryrefslogtreecommitdiff
path: root/src/mirrored_supervisor.erl
diff options
context:
space:
mode:
authorSimon MacMullen <simon@rabbitmq.com>2011-08-09 13:12:37 +0100
committerSimon MacMullen <simon@rabbitmq.com>2011-08-09 13:12:37 +0100
commit5e08ff22e9b37484073873120b130c7ff6b75ee5 (patch)
tree4f4233bb7ba51eabc5c2be558b70f62506be5987 /src/mirrored_supervisor.erl
parent1810ad41e829855d850b70b9ca4a2f0bd79043d3 (diff)
downloadrabbitmq-server-5e08ff22e9b37484073873120b130c7ff6b75ee5.tar.gz
Blow up if we're asked for simple_one_for_one, more tests, try to handle Mod:init/1 returning ignore.
Diffstat (limited to 'src/mirrored_supervisor.erl')
-rw-r--r--src/mirrored_supervisor.erl47
1 files changed, 33 insertions, 14 deletions
diff --git a/src/mirrored_supervisor.erl b/src/mirrored_supervisor.erl
index bed24cfd..3ecff1ef 100644
--- a/src/mirrored_supervisor.erl
+++ b/src/mirrored_supervisor.erl
@@ -228,22 +228,36 @@
%%----------------------------------------------------------------------------
start_link(Group, Mod, Args) ->
- start_link0([], Group, Mod, Args).
+ start_link0([], Group, init(Mod, Args)).
start_link({local, SupName}, Group, Mod, Args) ->
- start_link0([{local, SupName}], Group, Mod, Args);
+ start_link0([{local, SupName}], Group, init(Mod, Args));
start_link({global, _SupName}, _Group, _Mod, _Args) ->
error(badarg).
-start_link0(Prefix, Group, Mod, Args) ->
+start_link0(Prefix, Group, Init) ->
case apply(?SUPERVISOR, start_link,
- Prefix ++ [?MODULE, {overall, Group, Mod, Args}]) of
+ Prefix ++ [?MODULE, {overall, Group, Init}]) of
{ok, Pid} -> call(Pid, {init, Pid}),
{ok, Pid};
Other -> Other
end.
+init(Mod, Args) ->
+ case Mod:init(Args) of
+ Init = {ok, {Restart, _ChildSpecs}} ->
+ case Restart of
+ {Bad, _, _} when Bad =:= simple_one_for_one orelse
+ Bad =:= simple_one_for_one_terminate ->
+ error(badarg);
+ _ ->
+ Init
+ end;
+ ignore ->
+ ignore
+ end.
+
start_child(Sup, ChildSpec) -> call(Sup, {start_child, ChildSpec}).
delete_child(Sup, Name) -> call(Sup, {delete_child, Name}).
restart_child(Sup, Name) -> call(Sup, {msg, restart_child, [Name]}).
@@ -270,16 +284,21 @@ start_internal(Group, ChildSpecs) ->
%%----------------------------------------------------------------------------
-init({overall, Group, Mod, Args}) ->
- {ok, {Restart, ChildSpecs}} = Mod:init(Args),
- Delegate = {delegate, {?SUPERVISOR, start_link,
- [?MODULE, {delegate, Restart}]},
- temporary, 16#ffffffff, supervisor, [?SUPERVISOR]},
- Mirroring = {mirroring, {?MODULE, start_internal, [Group, ChildSpecs]},
- permanent, 16#ffffffff, worker, [?MODULE]},
- %% Important: Delegate MUST start after Mirroring, see comment in
- %% handle_info('DOWN', ...) below
- {ok, {{one_for_all, 0, 1}, [Mirroring, Delegate]}};
+init({overall, Group, Init}) ->
+ case Init of
+ {ok, {Restart, ChildSpecs}} ->
+ Delegate = {delegate, {?SUPERVISOR, start_link,
+ [?MODULE, {delegate, Restart}]},
+ temporary, 16#ffffffff, supervisor, [?SUPERVISOR]},
+ Mirroring = {mirroring, {?MODULE, start_internal,
+ [Group, ChildSpecs]},
+ permanent, 16#ffffffff, worker, [?MODULE]},
+ %% Important: Delegate MUST start after Mirroring, see comment in
+ %% handle_info('DOWN', ...) below
+ {ok, {{one_for_all, 0, 1}, [Mirroring, Delegate]}};
+ ignore ->
+ ignore
+ end;
init({delegate, Restart}) ->
{ok, {Restart, []}};