Signals end every command, not only ssh to and ssh install (closes #48)
check / check (push) Failing after 3s
check / check (push) Failing after 3s
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` put the encryption of the cut-off input in place. Now `ssh to` and `ssh install` catch them from once the mnemonic is read until their cleanup has run, and everywhere else they end the tool at once, except while `age encrypt -o` or `age decrypt -o` writes. There the work runs in the background, and a signal that comes before it ends, or within a tenth of a second after, removes the unfinished file and ends the tool with status 1, since Ctrl-C on a pipeline can end the input just before the signal arrives. Model: opus-5-5
This commit is contained in:
@@ -8,9 +8,11 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@@ -62,6 +64,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)
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user