exec: interrupt with delayed kill
This gives nix a chance to gracefully exit.
This commit is contained in:
parent
e2299a57d2
commit
4787f51d84
11
exec.go
11
exec.go
@ -5,7 +5,13 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"iter"
|
"iter"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
defaultWaitDelay = 15 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
// Nix is the name of the nix program.
|
// Nix is the name of the nix program.
|
||||||
@ -47,7 +53,10 @@ func New(ctx context.Context, extraArgs []string, stdout, stderr io.Writer) Cont
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (n *nix) Nix(ctx context.Context, arg ...string) *exec.Cmd {
|
func (n *nix) Nix(ctx context.Context, arg ...string) *exec.Cmd {
|
||||||
return exec.CommandContext(ctx, n.name, append(n.extra, arg...)...)
|
cmd := exec.CommandContext(ctx, n.name, append(n.extra, arg...)...)
|
||||||
|
cmd.Cancel = func() error { return cmd.Process.Signal(os.Interrupt) }
|
||||||
|
cmd.WaitDelay = defaultWaitDelay
|
||||||
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *nix) WriteStdin(cmd *exec.Cmd, installables iter.Seq[string], f func() error) (int, error) {
|
func (n *nix) WriteStdin(cmd *exec.Cmd, installables iter.Seq[string], f func() error) (int, error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user