diff options
author | José Valim <[email protected]> | 2016-03-31 10:34:15 +0200 |
---|---|---|
committer | José Valim <[email protected]> | 2016-06-04 23:00:07 +0200 |
commit | e2577531278c5dde283c4ab7be766d081c363ec3 (patch) | |
tree | 3285baa6cab800a705c15d889cacc934fb1d5681 /lib/stdlib/src/supervisor.erl | |
parent | 10a218b37324fd94ddbfe5568554de263492c82c (diff) | |
download | otp-e2577531278c5dde283c4ab7be766d081c363ec3.tar.gz otp-e2577531278c5dde283c4ab7be766d081c363ec3.tar.bz2 otp-e2577531278c5dde283c4ab7be766d081c363ec3.zip |
Return callback module in supervisor format_status
The previous implementation of supervisor:get_callback_module/1
used sys:get_status/1 to get the supervisor inner state and
retrieve the callback module. Such implementation forbids any
other supervisor implementation that has an internal state
different than the #state{} record in supervisor.erl.
This patch allows supervisors to return the callback module
as part of the sys:get_status/1 data, no longer coupling the
callback module implementation with the inner #state{} record.
Notice we have kept the clause matching the previous
sys:get_status/1 reply for backwards compatibility purposes.
Diffstat (limited to 'lib/stdlib/src/supervisor.erl')
-rw-r--r-- | lib/stdlib/src/supervisor.erl | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/stdlib/src/supervisor.erl b/lib/stdlib/src/supervisor.erl index 0400c845ab..205ed534ad 100644 --- a/lib/stdlib/src/supervisor.erl +++ b/lib/stdlib/src/supervisor.erl @@ -30,7 +30,7 @@ %% Internal exports -export([init/1, handle_call/3, handle_cast/2, handle_info/2, - terminate/2, code_change/3]). + terminate/2, code_change/3, format_status/2]). -export([try_again_restart/2]). %% For release_handler only @@ -264,8 +264,13 @@ cast(Supervisor, Req) -> get_callback_module(Pid) -> {status, _Pid, {module, _Mod}, [_PDict, _SysState, _Parent, _Dbg, Misc]} = sys:get_status(Pid), - [_Header, _Data, {data, [{"State", State}]}] = Misc, - State#state.module. + case lists:keyfind(supervisor, 1, Misc) of + {supervisor, [{"Callback", Mod}]} -> + Mod; + _ -> + [_Header, _Data, {data, [{"State", State}]} | _] = Misc, + State#state.module + end. %%% --------------------------------------------------- %%% @@ -1456,3 +1461,9 @@ report_progress(Child, SupName) -> Progress = [{supervisor, SupName}, {started, extract_child(Child)}], error_logger:info_report(progress, Progress). + +format_status(terminate, [_PDict, State]) -> + State; +format_status(_, [_PDict, State]) -> + [{data, [{"State", State}]}, + {supervisor, [{"Callback", State#state.module}]}]. |