Mailing List Archive

[Bug 3550] Key Conflict
https://bugzilla.mindrot.org/show_bug.cgi?id=3550

Damien Miller <djm@mindrot.org> changed:

What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |djm@mindrot.org
Resolution|--- |WORKSFORME

--- Comment #1 from Damien Miller <djm@mindrot.org> ---
You can use stty(1) to control the terminal's interpretation of ^C

E.g.

[djm@djm ~]$ ssh -t test "stty -isig; echo go; sleep 5; echo ok"
go
^C^C^C^C^C^C^C^C^Cok
Connection to test closed.

Without -isig, the ^C results in a SIGINT:

[djm@djm ~]$ ssh -t test "echo go; sleep 5; echo ok"go
^CConnection to test.mindrot.org closed.

--
You are receiving this mail because:
You are watching someone on the CC list of the bug.
You are watching the assignee of the bug.
_______________________________________________
openssh-bugs mailing list
openssh-bugs@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-bugs
[Bug 3550] Key Conflict [ In reply to ]
https://bugzilla.mindrot.org/show_bug.cgi?id=3550

Darren Tucker <dtucker@dtucker.net> changed:

What |Removed |Added
----------------------------------------------------------------------------
CC| |dtucker@dtucker.net

--- Comment #2 from Darren Tucker <dtucker@dtucker.net> ---
The remote program is getting a SIGINT because you told ssh to allocate
a controlling terminal and then sent it an interrupt.

You need to tell the remote shell or program to ignore the SIGINT. The
exact details will vary depending on the program and shell, but
assuming a Bourne-type shell one way to do this is to trap the SIGINT
in the shell to prevent it from being passed through to the program,
eg:

$ ssh -t localhost "trap '' INT; sleep 60"

--
You are receiving this mail because:
You are watching someone on the CC list of the bug.
You are watching the assignee of the bug.
_______________________________________________
openssh-bugs mailing list
openssh-bugs@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-bugs
[Bug 3550] Key Conflict [ In reply to ]
https://bugzilla.mindrot.org/show_bug.cgi?id=3550

--- Comment #3 from maggiezhuooo@163.com ---
(In reply to Damien Miller from comment #1)
> You can use stty(1) to control the terminal's interpretation of ^C
>
> E.g.
>
> [djm@djm ~]$ ssh -t test "stty -isig; echo go; sleep 5; echo ok"
> go
> ^C^C^C^C^C^C^C^C^Cok
> Connection to test closed.
>
> Without -isig, the ^C results in a SIGINT:
>
> [djm@djm ~]$ ssh -t test "echo go; sleep 5; echo ok"go
> ^CConnection to test.mindrot.org closed.

Thanks for the reply, but sorry maybe I didn't describe my question
clearly.
It is known that the default value of ^C in stty -intr , serves to
interrupt the current command. Now this ^C will make ssh exit under ssh
-t command.
I have tried changing the default value to ^N in the terminal, but ^N
only interrupts the command, ssh does not send SIGINT. I wonder if
there is a way to make ^C still act as a key to send SIGINT, but ssh
does not exit? Is there a way to replace the default ^C that causes ssh
to exit?

--
You are receiving this mail because:
You are watching someone on the CC list of the bug.
You are watching the assignee of the bug.
_______________________________________________
openssh-bugs mailing list
openssh-bugs@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-bugs
[Bug 3550] Key Conflict [ In reply to ]
https://bugzilla.mindrot.org/show_bug.cgi?id=3550

--- Comment #4 from Darren Tucker <dtucker@dtucker.net> ---
(In reply to maggiezhuooo from comment #3)
> Now this ^C will make ssh exit under ssh -t command.

That's probably not what's happening. What's probably happening is
that the ssh is forwarding the SIGINT to the server which is delivering
it to the remote program, which then exits. When it exits, the ssh
reads its exit status then exits itself. You can see this if you turn
on ssh debugging:

$ ssh -v -t localhost sleep 60
[...]
debug1: Sending command: sleep 60
^C
debug1: client_input_channel_req: channel 0 rtype exit-signal reply 0
debug1: client_input_channel_req: channel 0 rtype eow@openssh.com reply
0
debug1: channel 0: free: client-session, nchannels 1
Connection to localhost closed.


Could you elaborate on what you're trying to do?

--
You are receiving this mail because:
You are watching someone on the CC list of the bug.
You are watching the assignee of the bug.
_______________________________________________
openssh-bugs mailing list
openssh-bugs@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-bugs
[Bug 3550] Key Conflict [ In reply to ]
https://bugzilla.mindrot.org/show_bug.cgi?id=3550

--- Comment #5 from maggiezhuooo@163.com ---
(In reply to Darren Tucker from comment #4)
> (In reply to maggiezhuooo from comment #3)
> > Now this ^C will make ssh exit under ssh -t command.
>
> That's probably not what's happening. What's probably happening is
> that the ssh is forwarding the SIGINT to the server which is
> delivering it to the remote program, which then exits. When it
> exits, the ssh reads its exit status then exits itself. You can see
> this if you turn on ssh debugging:
>
> $ ssh -v -t localhost sleep 60
> [...]
> debug1: Sending command: sleep 60
> ^C
> debug1: client_input_channel_req: channel 0 rtype exit-signal reply 0
> debug1: client_input_channel_req: channel 0 rtype eow@openssh.com
> reply 0
> debug1: channel 0: free: client-session, nchannels 1
> Connection to localhost closed.
>
>
> Could you elaborate on what you're trying to do?

Thanks for your reply!
Sorry to bother you again, but when I run an app on a remote server
using ssh -t command, when I type ^c, the app stops running and SSH
shuts down with it. I want SSH to not shut down with the app stopping,
i.e. when the app returns to a stopped state, is there a way to make
SSH ignore this state and continue running? Because I want to continue
to use ssh to interact with the remote server.

--
You are receiving this mail because:
You are watching the assignee of the bug.
You are watching someone on the CC list of the bug.
_______________________________________________
openssh-bugs mailing list
openssh-bugs@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-bugs
[Bug 3550] Key Conflict [ In reply to ]
https://bugzilla.mindrot.org/show_bug.cgi?id=3550

--- Comment #6 from Darren Tucker <dtucker@dtucker.net> ---
(In reply to maggiezhuooo from comment #5)
> Sorry to bother you again, but when I run an app on a remote server
> using ssh -t command, when I type ^c, the app stops running and SSH
> shuts down with it. I want SSH to not shut down with the app
> stopping, i.e. when the app returns to a stopped state, is there a
> way to make SSH ignore this state and continue running? Because I
> want to continue to use ssh to interact with the remote server.

Depends on what exactly you want it to do. If you want the app to do
something other than exit on receipt of SIGINT, you need to somehow
tell the app to do something different.

If you want the app to exit but ssh to keep the shell up it's possible
although a bit convoluted: you need the remote login shell to kill its
child on receipt of SIGINT but not die itself, then invoke an
interactive shell for you to interact with, something like:

$ ssh -v -t localhost "trap 'kill -INT -$$' INT; sleep 60;
PS1='remoteshell$ ' sh -i"
[...]
^Cremoteshell$ exit
[...]
debug1: Exit status 0

The trap sends a SIGINT to the process group of the login shell which
includes the "app", which exits, causing the login shell to start
another (interactive) shell.

--
You are receiving this mail because:
You are watching someone on the CC list of the bug.
You are watching the assignee of the bug.
_______________________________________________
openssh-bugs mailing list
openssh-bugs@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-bugs
[Bug 3550] Key Conflict [ In reply to ]
https://bugzilla.mindrot.org/show_bug.cgi?id=3550

--- Comment #7 from Darren Tucker <dtucker@dtucker.net> ---
(In reply to Darren Tucker from comment #6)
[...]
> $ ssh -v -t localhost "trap 'kill -INT -$$' INT; sleep 60;
> PS1='remoteshell$ ' sh -i"

BTW I got the quoting on that wrong, but it happened to work because I
used localhost so the pid from the expanded $$ matched. For a remote
host, you would need to single-quote or escape the $$:

$ ssh -v -t somehost 'trap "kill -INT -$$; echo sig" INT; sleep 60;
PS1="remoteshell$ " sh -i'

--
You are receiving this mail because:
You are watching the assignee of the bug.
You are watching someone on the CC list of the bug.
_______________________________________________
openssh-bugs mailing list
openssh-bugs@mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-bugs