77defmodule RabbitMQ.CLI.Diagnostics.Commands.RemoteShellCommand do
88 @ behaviour RabbitMQ.CLI.CommandBehaviour
99 @ dialyzer :no_missing_calls
10+ @ dialyzer { :nowarn_function , [ run: 2 , start_shell_on_otp_26_plus: 1 , start_shell_on_otp_25: 1 ] }
1011
1112 use RabbitMQ.CLI.Core.MergesNoDefaults
1213 use RabbitMQ.CLI.Core.AcceptsNoPositionalArguments
@@ -15,18 +16,9 @@ defmodule RabbitMQ.CLI.Diagnostics.Commands.RemoteShellCommand do
1516 _ = :c . l ( :shell )
1617
1718 if :erlang . function_exported ( :shell , :start_interactive , 1 ) do
18- :shell . start_interactive ( { node_name , :shell , :start , [ ] } )
19- :timer . sleep ( :infinity )
19+ start_shell_on_otp_26_plus ( node_name )
2020 else
21- _ = Supervisor . terminate_child ( :kernel_sup , :user )
22- Process . flag ( :trap_exit , true )
23- user_drv = :user_drv . start ( [ ~c" tty_sl -c -e" , { node_name , :shell , :start , [ ] } ] )
24- Process . link ( user_drv )
25-
26- receive do
27- { ~c" EXIT" , _user_drv , _ } ->
28- { :ok , "Disconnected from #{ node_name } ." }
29- end
21+ start_shell_on_otp_25 ( node_name )
3022 end
3123 end
3224
@@ -41,4 +33,26 @@ defmodule RabbitMQ.CLI.Diagnostics.Commands.RemoteShellCommand do
4133 def banner ( _ , % { node: node_name } ) do
4234 "Starting an interactive Erlang shell on node #{ node_name } ... Press 'Ctrl+G' then 'q' to exit."
4335 end
36+
37+ defp start_shell_on_otp_26_plus ( node_name ) do
38+ case :shell . start_interactive ( { node_name , { :shell , :start , [ ] } } ) do
39+ :ok -> :ok
40+ { :error , :already_started } -> :ok
41+ { error , _ } -> { :error , { :badrpc , :nodedown } }
42+ end
43+
44+ :timer . sleep ( :infinity )
45+ end
46+
47+ defp start_shell_on_otp_25 ( node_name ) do
48+ _ = Supervisor . terminate_child ( :kernel_sup , :user )
49+ Process . flag ( :trap_exit , true )
50+ user_drv = :user_drv . start ( [ ~c" tty_sl -c -e" , { node_name , :shell , :start , [ ] } ] )
51+ Process . link ( user_drv )
52+
53+ receive do
54+ { ~c" EXIT" , _user_drv , _ } ->
55+ { :ok , "Disconnected from #{ node_name } ." }
56+ end
57+ end
4458end
0 commit comments