Skip to content

Commit

Permalink
fix: pass os Interupt to child process
Browse files Browse the repository at this point in the history
  • Loading branch information
faiq committed Oct 17, 2024
1 parent 79632ee commit b0bbf87
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions cmd/konvoy-image-wrapper/cmd/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,17 +369,25 @@ func (r *Runner) dockerRun(args []string) error {
cmd.Args = append(cmd.Args, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
subStdin, err := cmd.StdinPipe()
if err != nil {
return fmt.Errorf("failed to make pipe %w", err)
}
defer subStdin.Close()
cmd.SysProcAttr = &syscall.SysProcAttr{
Setsid: true,
Pdeathsig: syscall.SIGKILL,
}
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
defer signal.Stop(c)
go func() {
sig := <-c
if signalErr := cmd.Process.Signal(sig); signalErr != nil {
if signalErr := cmd.Process.Signal(os.Interrupt); signalErr != nil {
fmt.Fprintf(cmd.Stderr, "failed to relay signal %s %v\n", sig.String(), signalErr)
}
}()

err := cmd.Run()
err = cmd.Run()
if err != nil {
return fmt.Errorf("cmd failed %w", err)
}
Expand Down

0 comments on commit b0bbf87

Please sign in to comment.