Repository navigation
cp: restore the terminal when a signal hits the PIN prompt - #50
Merged
Merged
Conversation
term.ReadPassword clears ECHO and puts the old termios back from a deferred call, which a process killed by a signal never runs. At the PIN prompt nothing has registered for SIGINT yet -- connect does that later, around raw mode -- so Ctrl-C took the default disposition and died inside read(2), leaving a shell that no longer echoed anything typed into it. Reported on OpenWRT as #48. guardTerminal saves the state before the prompt and restores it from a signal handler: the same sync.Once-plus-goroutine arrangement setupInteractive uses, and for the same reason, which is that the signal path has to call os.Exit and os.Exit skips defers. connect and cp share makePINPrompt, so both were affected and both are covered. The test drives a real process on a real pty, because the fix exits via os.Exit. It fails without the guard, with ECHO as the only changed bit.
|
Hi @richlegrand , Inside OpenWRT, the The problem when closing (without this patch, that's using the stock v0.5.2) is that echo, newline and keys doesn't work; but all the window is cleared. Furthermore, if you launch After installing the And if I execute So, from my point of view the problem will be fixed with this patch. 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #48.
Ctrl-C at the
PIN:prompt left the terminal with echo off, so the usergot back a shell that showed nothing they typed.
term.ReadPasswordclearsECHOand puts the old termios back from adeferred call:
A process killed by a signal never runs its defers.
ISIGstays onduring the prompt, so Ctrl-C is a real SIGINT rather than an input byte,
and at that point in
connectnothing has registered for it yet --dialConnectis called atconnect.go:265, the firstsignal.Notifyisat
:303andterm.MakeRawat:380. So SIGINT took its defaultdisposition and killed the process inside
read(2), withECHOleftcleared.
guardTerminalsaves the state before the prompt and restores it from asignal handler. It is the same
sync.Once-plus-goroutine arrangementsetupInteractivealready uses, and for the same reason: the signal pathhas to call
os.Exit, which skips defers.connectandcpsharemakePINPrompt, so both were affected and bothare covered here.
Test
A pty test, since the fix exits via
os.Exitand cannot be exercisedin-process. It re-execs the test binary as a child on a real pty, waits
for the prompt to take hold, signals it, and asserts the terminal state
is bit-for-bit what it was. With the guard removed it fails, and the
delta is
Lflag35387 -> 35379 -- theECHObit and nothing else.creack/ptywas already a direct dependency, so this adds none.Not addressed
@lars18th also reported that
resetdoes not recover the terminal, andthat part is still unexplained. Echo-off accounts for the typing and the
arrow keys, but busybox's
resetapplet callsTCSETSWitself with echoon, so where it is compiled in it should have worked. Either the OpenWRT
build lacks the applet -- and
reset: not foundwould have beeninvisible with echo off -- or something beyond
ECHOis also being lost.stty -afrom a wedged shell would settle it. Worth confirming beforethe issue is closed, because if there is a second defect this does not
touch it.
Recovery in the meantime is to type
stty saneblind and press Enter.