aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ssh/src
diff options
context:
space:
mode:
authorHans Nilsson <[email protected]>2016-03-17 15:25:38 +0100
committerHans Nilsson <[email protected]>2016-03-18 14:48:20 +0100
commit7e9b90812b191bfbe7e775332fcbae62fca097da (patch)
treedcd1c74de184d140a9b151a71d95a08e62ec3f1c /lib/ssh/src
parentcb6b4b6c4a307239a714f6137ec93accfad0bd76 (diff)
downloadotp-7e9b90812b191bfbe7e775332fcbae62fca097da.tar.gz
otp-7e9b90812b191bfbe7e775332fcbae62fca097da.tar.bz2
otp-7e9b90812b191bfbe7e775332fcbae62fca097da.zip
ssh: Add ssh_info:collect/0 which returns all pids in the ssh supervisor tree
Good for test cases.
Diffstat (limited to 'lib/ssh/src')
-rw-r--r--lib/ssh/src/ssh_info.erl59
1 files changed, 58 insertions, 1 deletions
diff --git a/lib/ssh/src/ssh_info.erl b/lib/ssh/src/ssh_info.erl
index 652466c32b..2dfc55cd92 100644
--- a/lib/ssh/src/ssh_info.erl
+++ b/lib/ssh/src/ssh_info.erl
@@ -27,7 +27,8 @@
-export([print/0,
print/1,
- string/0
+ string/0,
+ collect_pids/0
]).
print() ->
@@ -219,3 +220,59 @@ loop(Acc) ->
Who ! {result,lists:flatten(lists:reverse(Acc))}
end.
+%%%################################################################
+collect_pids() -> collect_pids(ssh_sup).
+
+collect_pids(P) ->
+ Collector = pcollect_pids(P, spawn(fun init_collector/0)),
+ Collector ! {get_values,self()},
+ receive
+ {values,Values} ->
+ Values
+ end.
+
+%%%----------------
+pcollect_pids(undefined, Collector) ->
+ Collector;
+
+pcollect_pids(A, Collector) when is_atom(A) ->
+ pcollect_pids(whereis(A), Collector);
+
+pcollect_pids(Pid, Collector) when is_pid(Pid) ->
+ Collector ! {expect,Pid},
+ spawn(fun() ->
+ lists:foreach(
+ fun(P2) ->
+ pcollect_pids(P2,Collector)
+ end, children(Pid)),
+ Collector ! {value,Pid,Pid}
+ end),
+ Collector;
+
+pcollect_pids({_,Pid,supervisor,_}, Collector) when is_pid(Pid) ->
+ pcollect_pids(Pid, Collector);
+
+pcollect_pids({_,Pid,worker,_}, Collector) when is_pid(Pid) ->
+ Collector ! {value,Pid,Pid},
+ Collector;
+
+pcollect_pids(_, Collector) ->
+ Collector.
+
+%%%----------------
+init_collector() ->
+ loop_collector([],[]).
+
+loop_collector(Expects, Values) ->
+ receive
+ {expect, Ref} ->
+ loop_collector([Ref|Expects], Values);
+ {value, Ref, Val} ->
+ loop_collector(Expects--[Ref], [Val|Values]);
+ {get_values, From} when Expects==[] ->
+%% Values=/=[] ->
+ From ! {values,Values}
+ end.
+
+
+