aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ssh/src/ssh_system_sup.erl
diff options
context:
space:
mode:
authornick <[email protected]>2010-09-03 12:52:02 +0200
committernick <[email protected]>2010-09-03 12:52:02 +0200
commit8f67f51105560f1c0e721117100cf20d0c6061c0 (patch)
treed1c69b96672df5bf985914d9e3799168c41fdf82 /lib/ssh/src/ssh_system_sup.erl
parentf0c4e27ef0a5a365cab7b1dc69dbecf7856c3f3f (diff)
parentfddc1ed0341d13df8373509fa063d889fab8d219 (diff)
downloadotp-8f67f51105560f1c0e721117100cf20d0c6061c0.tar.gz
otp-8f67f51105560f1c0e721117100cf20d0c6061c0.tar.bz2
otp-8f67f51105560f1c0e721117100cf20d0c6061c0.zip
Merge branch 'nick/ssh/fix-process-leak/OTP-8807' into dev
* nick/ssh/fix-process-leak/OTP-8807: Fix race condition when terminating a connection. fix process leak in ssh_system_sup (dynamicaly created childs where not cleaned up)
Diffstat (limited to 'lib/ssh/src/ssh_system_sup.erl')
-rw-r--r--lib/ssh/src/ssh_system_sup.erl20
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/ssh/src/ssh_system_sup.erl b/lib/ssh/src/ssh_system_sup.erl
index 40db2e4adf..f4570b8a48 100644
--- a/lib/ssh/src/ssh_system_sup.erl
+++ b/lib/ssh/src/ssh_system_sup.erl
@@ -33,7 +33,8 @@
stop_system/2, system_supervisor/2,
subsystem_supervisor/1, channel_supervisor/1,
connection_supervisor/1,
- acceptor_supervisor/1, start_subsystem/2, restart_subsystem/2, restart_acceptor/2]).
+ acceptor_supervisor/1, start_subsystem/2, restart_subsystem/2,
+ restart_acceptor/2, stop_subsystem/2]).
%% Supervisor callback
-export([init/1]).
@@ -83,6 +84,23 @@ start_subsystem(SystemSup, Options) ->
Spec = ssh_subsystem_child_spec(Options),
supervisor:start_child(SystemSup, Spec).
+stop_subsystem(SystemSup, SubSys) ->
+ case lists:keyfind(SubSys, 2, supervisor:which_children(SystemSup)) of
+ false ->
+ {error, not_found};
+ {Id, _, _, _} ->
+ spawn(fun() -> supervisor:terminate_child(SystemSup, Id),
+ supervisor:delete_child(SystemSup, Id) end),
+ ok;
+ {'EXIT', {noproc, _}} ->
+ %% Already terminated; probably shutting down.
+ ok;
+ {'EXIT', {shutdown, _}} ->
+ %% Already shutting down.
+ ok
+ end.
+
+
restart_subsystem(Address, Port) ->
SysSupName = make_name(Address, Port),
SubSysName = id(ssh_subsystem_sup, Address, Port),