I have an ssh_cli handler that implements the ssh_server_channel behaviour, albeit written in Elixir, not Erlang. On receipt of the pty
message it looks up the capabilities of the terminal by issuing:
System.cmd("infocmp", ["-1", term_name], stderr_to_stdout: true)
It does some handling of the successful output from this command, returns from handle_ssh_msg/2
and then … exits - the client is immediately disconnected from their ssh session
It took me a little while to work out what was going on but I think it’s this:
- ssh_client_channel traps exits
-
System.cmd/3 does not handle its port’s
EXIT
message in its selective receive - The
EXIT
message is then handled by thessh_client_handler
- it hands it off back to my callback module. - My callback module doesn’t deal with this message
- The
ssh_client_handler
has explicit logic for catching function clauses that don’t deal with theEXIT
message, wherein it closes the connection.
I could handle the EXIT
message in handle_msg/2
, but that doesn’t seem quite right because I don’t know anything about the port itself - its all hidden behind System.cmd/3
.
Is the better thing to do here just to manage a port myself and, knowing that the hosting process is trapping exits, handle the normal EXIT
message and throw it away?