aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ssh/src/ssh_cli.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_cli.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_cli.erl')
-rw-r--r--lib/ssh/src/ssh_cli.erl28
1 files changed, 22 insertions, 6 deletions
diff --git a/lib/ssh/src/ssh_cli.erl b/lib/ssh/src/ssh_cli.erl
index e3b6ffa125..cb78acb84c 100644
--- a/lib/ssh/src/ssh_cli.erl
+++ b/lib/ssh/src/ssh_cli.erl
@@ -415,14 +415,12 @@ start_shell(ConnectionManager, State) ->
Shell = State#state.shell,
ShellFun = case is_function(Shell) of
true ->
+ {ok, User} =
+ ssh_userreg:lookup_user(ConnectionManager),
case erlang:fun_info(Shell, arity) of
{arity, 1} ->
- {ok, User} =
- ssh_userreg:lookup_user(ConnectionManager),
fun() -> Shell(User) end;
{arity, 2} ->
- {ok, User} =
- ssh_userreg:lookup_user(ConnectionManager),
{ok, PeerAddr} =
ssh_connection_manager:peer_addr(ConnectionManager),
fun() -> Shell(User, PeerAddr) end;
@@ -437,10 +435,28 @@ start_shell(ConnectionManager, State) ->
State#state{group = Group, buf = empty_buf()}.
start_shell(_ConnectionManager, Cmd, #state{exec={M, F, A}} = State) ->
- Group = group:start(self(), {M, F, A++[Cmd]}, [{echo,false}]),
+ Group = group:start(self(), {M, F, A++[Cmd]}, [{echo, false}]),
+ State#state{group = Group, buf = empty_buf()};
+start_shell(ConnectionManager, Cmd, #state{exec=Shell} = State) when is_function(Shell) ->
+ {ok, User} =
+ ssh_userreg:lookup_user(ConnectionManager),
+ ShellFun =
+ case erlang:fun_info(Shell, arity) of
+ {arity, 1} ->
+ fun() -> Shell(Cmd) end;
+ {arity, 2} ->
+ fun() -> Shell(Cmd, User) end;
+ {arity, 3} ->
+ {ok, PeerAddr} =
+ ssh_connection_manager:peer_addr(ConnectionManager),
+ fun() -> Shell(Cmd, User, PeerAddr) end;
+ _ ->
+ Shell
+ end,
+ Echo = get_echo(State#state.pty),
+ Group = group:start(self(), ShellFun, [{echo,Echo}]),
State#state{group = Group, buf = empty_buf()}.
-
% Pty can be undefined if the client never sets any pty options before
% starting the shell.
get_echo(undefined) ->