Skip to content

Commit 9011e66

Browse files
authored
Merge pull request #10253 from u3s/kuba/ssh/improve_ssh_stop_daemon/OTP-19801
ssh: use new supervisor:stop/1 function for stopping system
2 parents 1b0bced + 53e1f07 commit 9011e66

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
@@ -1605,11 +1605,10 @@ stop_listener(Config) when is_list(Config) ->
16051605
file:make_dir(UserDir),
16061606
SysDir = proplists:get_value(data_dir, Config),
16071607

1608-
{Pid0, Host, Port} = ssh_test_lib:daemon([{system_dir, SysDir},
1608+
{Pid, Host, Port} = ssh_test_lib:daemon([{system_dir, SysDir},
16091609
{user_dir, UserDir},
16101610
{password, "morot"},
16111611
{exec, fun ssh_exec_echo/1}]),
1612-
16131612
ConnectionRef0 = ssh_test_lib:connect(Host, Port,
16141613
[{silently_accept_hosts, true},
16151614
{user, "foo"},
@@ -1638,11 +1637,14 @@ stop_listener(Config) when is_list(Config) ->
16381637
ct:fail("Exec Timeout")
16391638
end,
16401639

1640+
%% Same daemon ref (Pid) is expected to be received below as
1641+
%% previously started system supervisor is still running and
1642+
%% assigned to Port
16411643
case ssh_test_lib:daemon(Port, [{system_dir, SysDir},
16421644
{user_dir, UserDir},
16431645
{password, "potatis"},
16441646
{exec, fun ssh_exec_echo/1}]) of
1645-
{Pid1, Host, Port} ->
1647+
{Pid, Host, Port} ->
16461648
ConnectionRef1 =
16471649
ssh_test_lib:connect(Host, Port, [{silently_accept_hosts, true},
16481650
{user, "foo"},
@@ -1655,13 +1657,12 @@ stop_listener(Config) when is_list(Config) ->
16551657
{password, "morot"},
16561658
{user_interaction, true},
16571659
{user_dir, UserDir}]),
1658-
ssh:close(ConnectionRef0),
1659-
ssh:close(ConnectionRef1),
1660-
ssh:stop_daemon(Pid0),
1661-
ssh:stop_daemon(Pid1);
1660+
ok = ssh:close(ConnectionRef0),
1661+
ok = ssh:close(ConnectionRef1),
1662+
ok = ssh:stop_daemon(Pid);
16621663
Error ->
16631664
ssh:close(ConnectionRef0),
1664-
ssh:stop_daemon(Pid0),
1665+
ssh:stop_daemon(Pid),
16651666
ct:fail({unexpected, Error})
16661667
end.
16671668

0 commit comments

Comments
 (0)