Skip to content

Commit 53e1f07

Browse files
committed
ssh: use new supervisor:stop/1 function for stopping system
- improve ssh_connection_SUITE:stop_listener test
1 parent 07d5b60 commit 53e1f07

File tree

4 files changed

+18
-22
lines changed

4 files changed

+18
-22
lines changed

lib/ssh/src/ssh.app.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,6 @@
7171
"erts-14.0",
7272
"kernel-10.3",
7373
"public_key-1.6.1",
74-
"stdlib-6.0","stdlib-5.0",
74+
"stdlib-@OTP-19800@",
7575
"runtime_tools-1.15.1"
7676
]}]}.

lib/ssh/src/ssh.erl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,12 @@ stop_daemon(Address, Port) ->
796796
stop_daemon(Address, Port, ?DEFAULT_PROFILE).
797797

798798

799-
-doc "Stops the listener and all connections started by the listener.".
799+
-doc """
800+
Stops the listener and all connections started by the listener.
801+
802+
If the daemon process does not exist, the call exits the calling process
803+
with reason `noproc`.
804+
""".
800805
-doc(#{since => <<"OTP 21.0">>}).
801806
-spec stop_daemon(any|inet:ip_address(), inet:port_number(), atom()) -> ok.
802807

lib/ssh/src/ssh_system_sup.erl

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,7 @@ start_system(Address0, Options) ->
7272

7373
%%%----------------------------------------------------------------
7474
stop_system(SysSup) when is_pid(SysSup) ->
75-
case lists:keyfind(SysSup, 2, supervisor:which_children(sup(server))) of
76-
{{?MODULE, Id}, SysSup, _, _} -> stop_system(Id);
77-
false -> ok
78-
end;
79-
stop_system(Id) ->
80-
supervisor:terminate_child(sup(server), {?MODULE, Id}).
81-
75+
supervisor:stop(SysSup).
8276

8377
%%%----------------------------------------------------------------
8478
stop_listener(SystemSup) when is_pid(SystemSup) ->
@@ -104,7 +98,7 @@ get_daemon_listen_address(SystemSup) ->
10498
%%% supervisor (callback = this module) for server and non-significant
10599
%%% child of sshc_sup for client
106100
start_connection(Role = client, _, Socket, Options) ->
107-
do_start_connection(Role, sup(client), false, Socket, Options);
101+
do_start_connection(Role, sshc_sup, false, Socket, Options);
108102
start_connection(Role = server, Address=#address{}, Socket, Options) ->
109103
case get_system_sup(Address, Options) of
110104
{ok, SysPid} ->
@@ -260,10 +254,6 @@ find_system_sup(Address0) ->
260254
[_,_|_] -> {error,ambiguous}
261255
end.
262256

263-
sup(client) -> sshc_sup;
264-
sup(server) -> sshd_sup.
265-
266-
267257
is_socket_server(Options) ->
268258
undefined =/= ?GET_INTERNAL_OPT(connected_socket,Options,undefined).
269259

lib/ssh/test/ssh_connection_SUITE.erl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,11 +1711,10 @@ stop_listener(Config) when is_list(Config) ->
17111711
file:make_dir(UserDir),
17121712
SysDir = proplists:get_value(data_dir, Config),
17131713

1714-
{Pid0, Host, Port} = ssh_test_lib:daemon([{system_dir, SysDir},
1714+
{Pid, Host, Port} = ssh_test_lib:daemon([{system_dir, SysDir},
17151715
{user_dir, UserDir},
17161716
{password, "morot"},
17171717
{exec, fun ssh_exec_echo/1}]),
1718-
17191718
ConnectionRef0 = ssh_test_lib:connect(Host, Port,
17201719
[{silently_accept_hosts, true},
17211720
{user, "foo"},
@@ -1744,11 +1743,14 @@ stop_listener(Config) when is_list(Config) ->
17441743
ct:fail("Exec Timeout")
17451744
end,
17461745

1746+
%% Same daemon ref (Pid) is expected to be received below as
1747+
%% previously started system supervisor is still running and
1748+
%% assigned to Port
17471749
case ssh_test_lib:daemon(Port, [{system_dir, SysDir},
17481750
{user_dir, UserDir},
17491751
{password, "potatis"},
17501752
{exec, fun ssh_exec_echo/1}]) of
1751-
{Pid1, Host, Port} ->
1753+
{Pid, Host, Port} ->
17521754
ConnectionRef1 =
17531755
ssh_test_lib:connect(Host, Port, [{silently_accept_hosts, true},
17541756
{user, "foo"},
@@ -1761,13 +1763,12 @@ stop_listener(Config) when is_list(Config) ->
17611763
{password, "morot"},
17621764
{user_interaction, true},
17631765
{user_dir, UserDir}]),
1764-
ssh:close(ConnectionRef0),
1765-
ssh:close(ConnectionRef1),
1766-
ssh:stop_daemon(Pid0),
1767-
ssh:stop_daemon(Pid1);
1766+
ok = ssh:close(ConnectionRef0),
1767+
ok = ssh:close(ConnectionRef1),
1768+
ok = ssh:stop_daemon(Pid);
17681769
Error ->
17691770
ssh:close(ConnectionRef0),
1770-
ssh:stop_daemon(Pid0),
1771+
ssh:stop_daemon(Pid),
17711772
ct:fail({unexpected, Error})
17721773
end.
17731774

0 commit comments

Comments
 (0)