Skip to content

Commit

Permalink
fix: Forward signals to child process
Browse files Browse the repository at this point in the history
  • Loading branch information
sestrella committed Dec 24, 2024
1 parent dcbb4d1 commit 9bf5eda
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion cmd/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"fmt"
"os"
"os/exec"
"os/signal"
"strings"
"syscall"

"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/ecs"
Expand Down Expand Up @@ -129,7 +131,35 @@ func runExec(ctx context.Context, smpPath string, client *ecs.Client, region str
smp.Stdin = os.Stdin
smp.Stdout = os.Stdout
smp.Stderr = os.Stderr
return smp.Run()

err = smp.Start()
if err != nil {
return err
}

sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

// TODO: handle errors
go func() {
for {
sig := <-sigs
switch sig {
case syscall.SIGINT:
err = syscall.Kill(smp.Process.Pid, syscall.SIGINT)
if err != nil {
panic(err)
}
case syscall.SIGTERM:
err = syscall.Kill(smp.Process.Pid, syscall.SIGTERM)
if err != nil {
panic(err)
}
}
}
}()

return smp.Wait()
}

func init() {
Expand Down

0 comments on commit 9bf5eda

Please sign in to comment.