carlos / platform Public

cli: re-raise the signal after restoring the terminal, not os.Exit

The code-health ratchet allows no new os.Exit in the root package. On
SIGINT or SIGTERM during the no-echo read, the terminal is restored,
the handler stopped and the signal sent again with its default action
(Kill where a process cannot signal itself, as on Windows).

Checked by hand on a pseudo-terminal: echo is off during the read, the
typed code never appears, and after Ctrl-C the process ends by SIGINT
with echo back on. The census envelope . is re-pinned for the change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev c9b7384f8cde5963f7af55c7f1c0471616570c7f parent 6181d32
2 files changed, +8 −4
  • domains_transfer_cli.go +7 −3
  • internal/provision/testdata/plan14-root-reads-domain-transfers.tsv +1 −1
diff --git a/domains_transfer_cli.go b/domains_transfer_cli.go
index 1be04faea..1d2fb04af 100644
--- a/domains_transfer_cli.go
+++ b/domains_transfer_cli.go
@@ -115,8 +115,9 @@ func runDomainsTransfer(args []string) error {
// readTransferCodeTerminal reads one line from the terminal fd without
// echoing it. The terminal is restored when the read returns, and on an
-// interrupt or termination during it, after which the process exits as
-// the signal would have it.
+// interrupt or termination during it, after which the signal is delivered
+// again with its default action, so the process ends as it would have
+// (where a signal cannot be sent to itself, as on Windows, it is killed).
func readTransferCodeTerminal(fd int) (string, error) {
state, err := term.GetState(fd)
if err != nil {
@@ -134,7 +135,10 @@ func readTransferCodeTerminal(fd int) (string, error) {
case sig := <-signals:
_ = term.Restore(fd, state)
fmt.Fprintln(os.Stderr)
- os.Exit(signalExit(sig))
+ signal.Stop(signals)
+ if self, err := os.FindProcess(os.Getpid()); err == nil && self.Signal(sig) != nil {
+ _ = self.Kill()
+ }
case <-done:
}
}()
diff --git a/internal/provision/testdata/plan14-root-reads-domain-transfers.tsv b/internal/provision/testdata/plan14-root-reads-domain-transfers.tsv
index 5b71f36c0..fa1a3f30c 100644
--- a/internal/provision/testdata/plan14-root-reads-domain-transfers.tsv
+++ b/internal/provision/testdata/plan14-root-reads-domain-transfers.tsv
@@ -1,4 +1,4 @@
# Census overlay domain-transfers, written by census-propose (#369). census-ruling-domain-transfers, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-domain-transfers.md.
# 0 body, 0 sites, 2 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
-@coverage . d7572d2fed9f5800c4d48bed6b3098bf7e38dc4005521067e2e58fa3ca37136a
+@coverage . b38afecfe2f7bcc8efbcb700134cf51025bcb6eb3375c2a3078bc15cdc7f26c5
@coverage internal/registrar e21ce8885350c0ad730c1a885568f4c07af266a1b4d6b4c50b063df76e666798