Created
September 12, 2009 03:47
-
-
Save boorad/185715 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%----------------------------------------------------------------- | |
%% Func: get_supervised_procs/0 | |
%% Purpose: This is the magic function. It finds all process in | |
%% the system and which modules they execute as a call_back or | |
%% process module. | |
%% This is achieved by asking the main supervisor for the | |
%% applications for all children and their modules | |
%% (recursively). | |
%% NOTE: If a supervisor is suspended, it isn't possible to call | |
%% which_children. Code change on a supervisor should be | |
%% done in another way; the only code in a supervisor is | |
%% code for starting children. Therefore, to change a | |
%% supervisor module, we should load the new version, and then | |
%% delete the old. Then we should perform the start changes | |
%% manually, by adding/deleting children. | |
%% Returns: [{SuperPid, ChildName, ChildPid, Mods}] | |
%%----------------------------------------------------------------- | |
%% OTP-3452. For each application the first item contains the pid | |
%% of the top supervisor, and the name of the supervisor call-back module. | |
%%----------------------------------------------------------------- | |
get_supervised_procs() -> | |
lists:foldl( | |
fun(Application, Procs) -> | |
case application_controller:get_master(Application) of | |
Pid when is_pid(Pid) -> | |
{Root, _AppMod} = application_master:get_child(Pid), | |
case get_supervisor_module(Root) of | |
{ok, SupMod} -> | |
get_procs(supervisor:which_children(Root), | |
Root) ++ | |
[{undefined, undefined, Root, [SupMod]} | | |
Procs]; | |
{error, _} -> | |
error_logger:error_msg("release_handler: " | |
"cannot find top " | |
"supervisor for " | |
"application ~w~n", | |
[Application]), | |
get_procs(supervisor:which_children(Root), | |
Root) ++ Procs | |
end; | |
_ -> Procs | |
end | |
end, | |
[], | |
lists:map(fun({Application, _Name, _Vsn}) -> | |
Application | |
end, | |
application:which_applications())). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment