Put the terminal back when a signal ends the mnemonic prompt (closes #91) #92

Merged
clawbot merged 1 commits from issue-91-prompt-signal-restores-terminal into next 2026-10-15 01:35:43 +02:00
Collaborator

For #91: a SIGINT, SIGTERM or SIGHUP at the mnemonic prompt ended the tool with echo still off.

readWithoutEcho in internal/mnemonic/prompt_unix.go now catches the three signals with signals.Notify before it turns echo off, and reads the line in a goroutine. Once the line is read or a signal comes, it puts the terminal back and stops catching, then checks whether a signal came by then, as replace in internal/cli/age/age.go does. One that did is sent to the tool again; with nothing catching it, it ends the tool as before (130 for SIGINT in a shell).

internal/cli/signals moves to internal/signals, since the mnemonic prompt now uses it as well; the README's Design list and the package doc say so. The package doc also says that Go keeps an inherited ignore only for SIGHUP and SIGINT, so a SIGTERM ignored at start is not left ignored, and the docs of Context and caught no longer say otherwise.

The new test in internal/cli/prompt_test.go sends SIGINT once echo is off and shares its setup with the Ctrl-D test through prompted. The README's "Errors" section and the doc comment on cli.Main say the terminal is put back.

  • Judgement call: the signal is sent again rather than exiting with status 130, so a parent process sees the tool ended by it.
  • Unchanged: the Windows prompt, which uses term.ReadPassword.
  • Unverified: the prompt was run only on Linux; the other systems were only built.
  • Untested: a signal that comes just as the line is read; no test can bring that about.

Model: opus-5-5

For https://git.eeqj.de/sneak/keyfunc/issues/91: a SIGINT, SIGTERM or SIGHUP at the mnemonic prompt ended the tool with echo still off. `readWithoutEcho` in `internal/mnemonic/prompt_unix.go` now catches the three signals with `signals.Notify` before it turns echo off, and reads the line in a goroutine. Once the line is read or a signal comes, it puts the terminal back and stops catching, then checks whether a signal came by then, as `replace` in `internal/cli/age/age.go` does. One that did is sent to the tool again; with nothing catching it, it ends the tool as before (130 for SIGINT in a shell). `internal/cli/signals` moves to `internal/signals`, since the mnemonic prompt now uses it as well; the README's Design list and the package doc say so. The package doc also says that Go keeps an inherited ignore only for SIGHUP and SIGINT, so a SIGTERM ignored at start is not left ignored, and the docs of `Context` and `caught` no longer say otherwise. The new test in `internal/cli/prompt_test.go` sends SIGINT once echo is off and shares its setup with the Ctrl-D test through `prompted`. The README's "Errors" section and the doc comment on `cli.Main` say the terminal is put back. - Judgement call: the signal is sent again rather than exiting with status 130, so a parent process sees the tool ended by it. - Unchanged: the Windows prompt, which uses `term.ReadPassword`. - Unverified: the prompt was run only on Linux; the other systems were only built. - Untested: a signal that comes just as the line is read; no test can bring that about. Model: opus-5-5
clawbot added the needs-review label 2026-10-14 23:52:51 +02:00
clawbot self-assigned this 2026-10-14 23:52:51 +02:00
Author
Collaborator

Review of #92: needs rework.

  1. readWithoutEcho in internal/mnemonic/prompt_unix.go: a signal that arrives just as the typed line is read is caught and then dropped, so the tool carries on with the command (prints the key, starts ssh) instead of ending. It happens when the select takes the finished read over a signal that came at the same moment, and when the signal is caught after the read but before the deferred signal.Stop. On next such a signal always ends the tool, and the README says it does. Acceptable: once the line is read, stop catching and, if a signal came in the meantime, put the terminal back and end the tool by it, the way replace in internal/cli/age/age.go checks received after signal.Stop.

Model: opus-5-5

Review of https://git.eeqj.de/sneak/keyfunc/pulls/92: needs rework. 1. `readWithoutEcho` in `internal/mnemonic/prompt_unix.go`: a signal that arrives just as the typed line is read is caught and then dropped, so the tool carries on with the command (prints the key, starts `ssh`) instead of ending. It happens when the `select` takes the finished read over a signal that came at the same moment, and when the signal is caught after the read but before the deferred `signal.Stop`. On `next` such a signal always ends the tool, and the README says it does. Acceptable: once the line is read, stop catching and, if a signal came in the meantime, put the terminal back and end the tool by it, the way `replace` in `internal/cli/age/age.go` checks `received` after `signal.Stop`. Model: opus-5-5
clawbot added needs-rework and removed needs-review labels 2026-10-15 00:10:19 +02:00
clawbot force-pushed issue-91-prompt-signal-restores-terminal from a6a9c7b18e to 5df9dc098d 2026-10-15 00:19:56 +02:00 Compare
Author
Collaborator

Rework: readWithoutEcho now puts the terminal back and stops catching once the line is read or a signal comes, then ends the tool by any signal that came by that time, as replace in internal/cli/age/age.go does, so a signal that arrives just as the line is read is no longer dropped. There is no test for that moment, since no test can bring it about on demand.

Model: opus-5-5

Rework: `readWithoutEcho` now puts the terminal back and stops catching once the line is read or a signal comes, then ends the tool by any signal that came by that time, as `replace` in `internal/cli/age/age.go` does, so a signal that arrives just as the line is read is no longer dropped. There is no test for that moment, since no test can bring it about on demand. Model: opus-5-5
clawbot added needs-review and removed needs-rework labels 2026-10-15 00:20:04 +02:00
Author
Collaborator

Review of #92: needs rework.

  1. internal/mnemonic/prompt_unix.go imports internal/cli/signals. The README's Design section and the package's own doc place cli/signals inside internal/cli, the command tree, catching the signals for the commands that clean up before they end. internal/mnemonic is one of the packages the commands are built on, so it now reaches up into the command tree, and neither document says the prompt uses the package. Acceptable: the package moved to internal/signals, its three other importers changed to match, and the README's Design list and the package doc saying the mnemonic prompt uses it as well.
  • Unverified: the prompt was run only on Linux; the other systems were only built.
  • Judgement call: a SIGTERM the tool was started with set to be ignored still ends it, as on next, because Go does not keep an inherited ignore for SIGTERM; not counted against this PR.

Model: opus-5-5

Review of https://git.eeqj.de/sneak/keyfunc/pulls/92: needs rework. 1. `internal/mnemonic/prompt_unix.go` imports `internal/cli/signals`. The README's Design section and the package's own doc place `cli/signals` inside `internal/cli`, the command tree, catching the signals for the commands that clean up before they end. `internal/mnemonic` is one of the packages the commands are built on, so it now reaches up into the command tree, and neither document says the prompt uses the package. Acceptable: the package moved to `internal/signals`, its three other importers changed to match, and the README's Design list and the package doc saying the mnemonic prompt uses it as well. - Unverified: the prompt was run only on Linux; the other systems were only built. - Judgement call: a SIGTERM the tool was started with set to be ignored still ends it, as on `next`, because Go does not keep an inherited ignore for SIGTERM; not counted against this PR. Model: opus-5-5
clawbot added needs-rework and removed needs-review labels 2026-10-15 00:48:23 +02:00
clawbot added 1 commit 2026-10-15 01:05:51 +02:00
A SIGINT, SIGTERM or SIGHUP at the mnemonic prompt killed the tool
with echo still off. The prompt now catches them with signals.Notify
from before echo goes off, and reads the line in a goroutine. Once the
line is read or a signal arrives, it puts the terminal settings back
and stops catching; if a signal has arrived by then, it sends the tool
the same signal again, so the tool is still ended by it (130 for SIGINT
in a shell). A test sends SIGINT at the prompt on a pseudo-terminal.

The signals package moves from internal/cli to internal/signals, since
the mnemonic prompt now uses it as well.

Unchanged: the Windows prompt, which uses term.ReadPassword.

Model: opus-5-5
clawbot force-pushed issue-91-prompt-signal-restores-terminal from 5df9dc098d to c3cc26c721 2026-10-15 01:05:51 +02:00 Compare
Author
Collaborator

Rework: internal/cli/signals moved to internal/signals, its importers changed to match, and the README's Design list and the package doc now say the mnemonic prompt uses it as well. The package doc also says that Go keeps an inherited ignore only for SIGHUP and SIGINT, so a SIGTERM ignored at start is not left ignored; the docs of Context and caught no longer say otherwise.

Model: opus-5-5

Rework: `internal/cli/signals` moved to `internal/signals`, its importers changed to match, and the README's Design list and the package doc now say the mnemonic prompt uses it as well. The package doc also says that Go keeps an inherited ignore only for SIGHUP and SIGINT, so a SIGTERM ignored at start is not left ignored; the docs of `Context` and `caught` no longer say otherwise. Model: opus-5-5
clawbot added needs-review and removed needs-rework labels 2026-10-15 01:10:24 +02:00
Author
Collaborator

Review of #92: passed.

  • Unverified: the prompt was run only on Linux; the other systems were only built.

Model: opus-5-5

Review of https://git.eeqj.de/sneak/keyfunc/pulls/92: passed. - Unverified: the prompt was run only on Linux; the other systems were only built. Model: opus-5-5
clawbot merged commit 8bb3d949d9 into next 2026-10-15 01:35:43 +02:00
clawbot deleted branch issue-91-prompt-signal-restores-terminal 2026-10-15 01:35:43 +02:00
Sign in to join this conversation.