File 1421-ssh-use-new-supervisor-stop-1-function-for-stopping-.patch of Package erlang
From 53e1f074cd70f9a28eefaa7c4229e2abc0f8cc4c Mon Sep 17 00:00:00 2001
From: Jakub Witczak <kuba@erlang.org>
Date: Thu, 2 Oct 2025 18:19:14 +0200
Subject: [PATCH] ssh: use new supervisor:stop/1 function for stopping system
- improve ssh_connection_SUITE:stop_listener test
---
lib/ssh/src/ssh.app.src | 2 +-
lib/ssh/src/ssh.erl | 7 ++++++-
lib/ssh/src/ssh_system_sup.erl | 14 ++------------
lib/ssh/test/ssh_connection_SUITE.erl | 17 +++++++++--------
4 files changed, 18 insertions(+), 22 deletions(-)
diff --git a/lib/ssh/src/ssh.app.src b/lib/ssh/src/ssh.app.src
index cfc33b77cc..d01ee51254 100644
--- a/lib/ssh/src/ssh.app.src
+++ b/lib/ssh/src/ssh.app.src
@@ -71,6 +71,6 @@
"erts-14.0",
"kernel-10.3",
"public_key-1.6.1",
- "stdlib-6.0","stdlib-5.0",
+ "stdlib-6-0",
"runtime_tools-1.15.1"
]}]}.
diff --git a/lib/ssh/src/ssh.erl b/lib/ssh/src/ssh.erl
index 5fb0251553..813bfb56ff 100644
--- a/lib/ssh/src/ssh.erl
+++ b/lib/ssh/src/ssh.erl
@@ -796,7 +796,12 @@ stop_daemon(Address, Port) ->
stop_daemon(Address, Port, ?DEFAULT_PROFILE).
--doc "Stops the listener and all connections started by the listener.".
+-doc """
+Stops the listener and all connections started by the listener.
+
+If the daemon process does not exist, the call exits the calling process
+with reason `noproc`.
+""".
-doc(#{since => <<"OTP 21.0">>}).
-spec stop_daemon(any|inet:ip_address(), inet:port_number(), atom()) -> ok.
diff --git a/lib/ssh/src/ssh_system_sup.erl b/lib/ssh/src/ssh_system_sup.erl
index 33434591ff..bee6faab4d 100644
--- a/lib/ssh/src/ssh_system_sup.erl
+++ b/lib/ssh/src/ssh_system_sup.erl
@@ -72,13 +72,7 @@ start_system(Address0, Options) ->
%%%----------------------------------------------------------------
stop_system(SysSup) when is_pid(SysSup) ->
- case lists:keyfind(SysSup, 2, supervisor:which_children(sup(server))) of
- {{?MODULE, Id}, SysSup, _, _} -> stop_system(Id);
- false -> ok
- end;
-stop_system(Id) ->
- supervisor:terminate_child(sup(server), {?MODULE, Id}).
-
+ supervisor:stop(SysSup).
%%%----------------------------------------------------------------
stop_listener(SystemSup) when is_pid(SystemSup) ->
@@ -104,7 +98,7 @@ get_daemon_listen_address(SystemSup) ->
%%% supervisor (callback = this module) for server and non-significant
%%% child of sshc_sup for client
start_connection(Role = client, _, Socket, Options) ->
- do_start_connection(Role, sup(client), false, Socket, Options);
+ do_start_connection(Role, sshc_sup, false, Socket, Options);
start_connection(Role = server, Address=#address{}, Socket, Options) ->
case get_system_sup(Address, Options) of
{ok, SysPid} ->
@@ -260,10 +254,6 @@ find_system_sup(Address0) ->
[_,_|_] -> {error,ambiguous}
end.
-sup(client) -> sshc_sup;
-sup(server) -> sshd_sup.
-
-
is_socket_server(Options) ->
undefined =/= ?GET_INTERNAL_OPT(connected_socket,Options,undefined).
diff --git a/lib/ssh/test/ssh_connection_SUITE.erl b/lib/ssh/test/ssh_connection_SUITE.erl
index f4b2248180..8fbc11a8f8 100644
--- a/lib/ssh/test/ssh_connection_SUITE.erl
+++ b/lib/ssh/test/ssh_connection_SUITE.erl
@@ -1711,11 +1711,10 @@ stop_listener(Config) when is_list(Config) ->
file:make_dir(UserDir),
SysDir = proplists:get_value(data_dir, Config),
- {Pid0, Host, Port} = ssh_test_lib:daemon([{system_dir, SysDir},
+ {Pid, Host, Port} = ssh_test_lib:daemon([{system_dir, SysDir},
{user_dir, UserDir},
{password, "morot"},
{exec, fun ssh_exec_echo/1}]),
-
ConnectionRef0 = ssh_test_lib:connect(Host, Port,
[{silently_accept_hosts, true},
{user, "foo"},
@@ -1744,11 +1743,14 @@ stop_listener(Config) when is_list(Config) ->
ct:fail("Exec Timeout")
end,
+ %% Same daemon ref (Pid) is expected to be received below as
+ %% previously started system supervisor is still running and
+ %% assigned to Port
case ssh_test_lib:daemon(Port, [{system_dir, SysDir},
{user_dir, UserDir},
{password, "potatis"},
{exec, fun ssh_exec_echo/1}]) of
- {Pid1, Host, Port} ->
+ {Pid, Host, Port} ->
ConnectionRef1 =
ssh_test_lib:connect(Host, Port, [{silently_accept_hosts, true},
{user, "foo"},
@@ -1761,13 +1763,12 @@ stop_listener(Config) when is_list(Config) ->
{password, "morot"},
{user_interaction, true},
{user_dir, UserDir}]),
- ssh:close(ConnectionRef0),
- ssh:close(ConnectionRef1),
- ssh:stop_daemon(Pid0),
- ssh:stop_daemon(Pid1);
+ ok = ssh:close(ConnectionRef0),
+ ok = ssh:close(ConnectionRef1),
+ ok = ssh:stop_daemon(Pid);
Error ->
ssh:close(ConnectionRef0),
- ssh:stop_daemon(Pid0),
+ ssh:stop_daemon(Pid),
ct:fail({unexpected, Error})
end.
--
2.51.0