From 4974184aa900e3770df69cb75da9a90bc6c01c1f Mon Sep 17 00:00:00 2001 From: Sebastian Estrella <2049686+sestrella@users.noreply.github.com> Date: Thu, 26 Dec 2024 23:12:32 -0500 Subject: [PATCH] Refactor using kubectl as a reference --- cmd/exec.go | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/cmd/exec.go b/cmd/exec.go index bf7bbe4..26db585 100644 --- a/cmd/exec.go +++ b/cmd/exec.go @@ -137,25 +137,14 @@ func runExec(ctx context.Context, smpPath string, client *ecs.Client, region str return err } - sigs := make(chan os.Signal, 1) - signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) - - // TODO: handle errors + // Reference: https://github.com/kubernetes/kubectl/blob/master/pkg/util/interrupt/interrupt.go go func() { - for { - sig := <-sigs - switch sig { - case syscall.SIGINT: - err = syscall.Kill(cmd.Process.Pid, syscall.SIGINT) - if err != nil { - panic(err) - } - case syscall.SIGTERM: - err = syscall.Kill(cmd.Process.Pid, syscall.SIGTERM) - if err != nil { - panic(err) - } - } + 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) } }()