Skip to content

Commit

Permalink
fix: Forward signals to child process (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
sestrella authored Dec 27, 2024
1 parent dcbb4d1 commit 09aa6df
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions 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 @@ -118,18 +120,35 @@ func runExec(ctx context.Context, smpPath string, client *ecs.Client, region str
return err
}
// https://github.com/aws/aws-cli/blob/develop/awscli/customizations/ecs/executecommand.py
smp := exec.Command(smpPath,
cmd := exec.Command(smpPath,
string(session),
region,
"StartSession",
"",
string(targetJSON),
fmt.Sprintf("https://ssm.%s.amazonaws.com", region),
)
smp.Stdin = os.Stdin
smp.Stdout = os.Stdout
smp.Stderr = os.Stderr
return smp.Run()
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

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

// Reference: https://github.com/kubernetes/kubectl/blob/master/pkg/util/interrupt/interrupt.go
go func() {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM)
sig := <-sigs
err = cmd.Process.Signal(sig)
if err != nil {
panic(err)
}
}()

return cmd.Wait()
}

func init() {
Expand Down

0 comments on commit 09aa6df

Please sign in to comment.