Signals end every command, not only ssh to and ssh install (closes #48)
check / check (push) Successful in 2m35s

SIGINT, SIGTERM and SIGHUP were caught for the whole run, but only the
ssh and sftp children acted on them: the mnemonic prompt waited for
Enter, and an interrupted `age encrypt -o` went on to put the
encryption of the cut-off input in place. Now only `ssh to` and
`ssh install` catch them, from once the mnemonic is read until their
cleanup has run; everywhere else they end the tool at once. Tests cover
an interrupted `age encrypt -o` and the install working directory on a
signal.

Model: opus-5-5
This commit is contained in:
2026-10-04 04:40:57 +00:00
parent 1ddc2c747a
commit ca1faa5551
6 changed files with 163 additions and 22 deletions
+13
View File
@@ -7,9 +7,11 @@ import (
"fmt"
"os"
"os/exec"
"os/signal"
"path/filepath"
"slices"
"strings"
"syscall"
"github.com/spf13/cobra"
)
@@ -55,6 +57,17 @@ func install() *cobra.Command {
return err
}
// From here on a signal cancels the context, which
// sftp runs under, instead of ending the tool, so sftp
// ends and the working directory is still removed.
ctx, stop := signal.NotifyContext(
cmd.Context(),
syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP,
)
defer stop()
cmd.SetContext(ctx)
return add(cmd, args[0], args[1:], line)
},
}