Skip to content

Commit

Permalink
fix: adds signal handling
Browse files Browse the repository at this point in the history
  • Loading branch information
faiq committed Aug 28, 2024
1 parent 7263d2a commit 8dc7fd4
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion cmd/konvoy-image-wrapper/cmd/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import (
"log"
"os"
"os/exec"
"os/signal"
"os/user"
"path/filepath"
"runtime"
"strconv"
"strings"
"syscall"

"github.com/mitchellh/go-homedir"

Expand Down Expand Up @@ -368,6 +370,16 @@ func (r *Runner) dockerRun(args []string) error {
cmd.Args = append(cmd.Args, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
defer signal.Stop(c)
go func() {
for sig := range c {
if signalErr := cmd.Process.Signal(sig); signalErr != nil {
fmt.Fprintf(cmd.Stderr, "failed to relay signal %s %v\n", sig.String(), signalErr)
}
}
}()

err := cmd.Run()
if err != nil {
Expand Down Expand Up @@ -503,7 +515,10 @@ func (r *Runner) Run(args []string) error {
if err != nil {
return fmt.Errorf("failed to make temp %w", err)
}
defer os.RemoveAll(r.tempDir)
defer func() {
fmt.Println("Removing temporary directory", r.tempDir)
os.RemoveAll(r.tempDir)
}()

// Setup the user and group mappings in the container so that uid and
// gid on the host can be properly resolved in the container too.
Expand Down

0 comments on commit 8dc7fd4

Please sign in to comment.