diff options
author | Loïc Hoguin <[email protected]> | 2018-03-13 10:40:14 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2018-03-13 10:40:14 +0100 |
commit | b9c8d86502a76cf3a72af30fc6aa0fc88ca7afff (patch) | |
tree | c4904971099917551801c26f22b6283c869e4937 /src/cowboy_children.erl | |
parent | a89732e8e0fac2b2265007a11c05d4d0f6e6b1b0 (diff) | |
download | cowboy-b9c8d86502a76cf3a72af30fc6aa0fc88ca7afff.tar.gz cowboy-b9c8d86502a76cf3a72af30fc6aa0fc88ca7afff.tar.bz2 cowboy-b9c8d86502a76cf3a72af30fc6aa0fc88ca7afff.zip |
Handle supervisor calls properly everywhere
Diffstat (limited to 'src/cowboy_children.erl')
-rw-r--r-- | src/cowboy_children.erl | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/cowboy_children.erl b/src/cowboy_children.erl index 1927a5a..05d39fb 100644 --- a/src/cowboy_children.erl +++ b/src/cowboy_children.erl @@ -20,8 +20,7 @@ -export([shutdown/2]). -export([shutdown_timeout/3]). -export([terminate/1]). --export([which_children/2]). --export([count_children/1]). +-export([handle_supervisor_call/4]). -record(child, { pid :: pid(), @@ -160,6 +159,24 @@ longest_shutdown_time([#child{shutdown=ChildTime}|Tail], Time) when ChildTime > longest_shutdown_time([_|Tail], Time) -> longest_shutdown_time(Tail, Time). +-spec handle_supervisor_call(any(), {pid(), any()}, children(), module()) -> ok. +handle_supervisor_call(which_children, {From, Tag}, Children, Module) -> + From ! {Tag, which_children(Children, Module)}, + ok; +handle_supervisor_call(count_children, {From, Tag}, Children, _) -> + From ! {Tag, count_children(Children)}, + ok; +%% We disable start_child since only incoming requests +%% end up creating a new process. +handle_supervisor_call({start_child, _}, {From, Tag}, _, _) -> + From ! {Tag, {error, start_child_disabled}}, + ok; +%% All other calls refer to children. We act in a similar way +%% to a simple_one_for_one so we never find those. +handle_supervisor_call(_, {From, Tag}, _, _) -> + From ! {Tag, {error, not_found}}, + ok. + -spec which_children(children(), module()) -> [{module(), pid(), worker, [module()]}]. which_children(Children, Module) -> [{Module, Pid, worker, [Module]} || #child{pid=Pid} <- Children]. |