aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/src
diff options
context:
space:
mode:
authorRory Byrne <[email protected]>2015-05-28 15:48:42 +0100
committerRory Byrne <[email protected]>2015-06-09 18:57:40 +0100
commitb74a978af2253773a2d74876d4f4abccde25a673 (patch)
treec190947394d4efe94586203b7642e9c5ff450342 /lib/stdlib/src
parentf1dede329de90e4805cd21a43bb5b19e288c81a3 (diff)
downloadotp-b74a978af2253773a2d74876d4f4abccde25a673.tar.gz
otp-b74a978af2253773a2d74876d4f4abccde25a673.tar.bz2
otp-b74a978af2253773a2d74876d4f4abccde25a673.zip
Fix supervisor:get_childspec/2 for simple_one_for_one
A bug in supervisor:get_childspec/2 results in {error, simple_one_for_one} being returned on every call when the supervisor strategy is simple_one_for_one. This commit includes a small refactoring which brings together the two 'start_child' clauses to make the code easier to follow.
Diffstat (limited to 'lib/stdlib/src')
-rw-r--r--lib/stdlib/src/supervisor.erl27
1 files changed, 15 insertions, 12 deletions
diff --git a/lib/stdlib/src/supervisor.erl b/lib/stdlib/src/supervisor.erl
index 1d7396adee..ac51bb3b79 100644
--- a/lib/stdlib/src/supervisor.erl
+++ b/lib/stdlib/src/supervisor.erl
@@ -393,6 +393,15 @@ handle_call({start_child, EArgs}, _From, State) when ?is_simple(State) ->
{reply, What, State}
end;
+handle_call({start_child, ChildSpec}, _From, State) ->
+ case check_childspec(ChildSpec) of
+ {ok, Child} ->
+ {Resp, NState} = handle_start_child(Child, State),
+ {reply, Resp, NState};
+ What ->
+ {reply, {error, What}, State}
+ end;
+
%% terminate_child for simple_one_for_one can only be done with pid
handle_call({terminate_child, Name}, _From, State) when not is_pid(Name),
?is_simple(State) ->
@@ -411,20 +420,10 @@ handle_call({terminate_child, Name}, _From, State) ->
{reply, {error, not_found}, State}
end;
-%%% The requests delete_child and restart_child are invalid for
-%%% simple_one_for_one supervisors.
-handle_call({_Req, _Data}, _From, State) when ?is_simple(State) ->
+%% restart_child request is invalid for simple_one_for_one supervisors
+handle_call({restart_child, _Name}, _From, State) when ?is_simple(State) ->
{reply, {error, simple_one_for_one}, State};
-handle_call({start_child, ChildSpec}, _From, State) ->
- case check_childspec(ChildSpec) of
- {ok, Child} ->
- {Resp, NState} = handle_start_child(Child, State),
- {reply, Resp, NState};
- What ->
- {reply, {error, What}, State}
- end;
-
handle_call({restart_child, Name}, _From, State) ->
case get_child(Name, State) of
{value, Child} when Child#child.pid =:= undefined ->
@@ -446,6 +445,10 @@ handle_call({restart_child, Name}, _From, State) ->
{reply, {error, not_found}, State}
end;
+%% delete_child request is invalid for simple_one_for_one supervisors
+handle_call({delete_child, _Name}, _From, State) when ?is_simple(State) ->
+ {reply, {error, simple_one_for_one}, State};
+
handle_call({delete_child, Name}, _From, State) ->
case get_child(Name, State) of
{value, Child} when Child#child.pid =:= undefined ->