diff --git a/go.mod b/go.mod index 80eca7d..064c3c1 100644 --- a/go.mod +++ b/go.mod @@ -11,6 +11,7 @@ require ( github.com/hashicorp/vault/api/auth/kubernetes v0.6.0 github.com/samber/lo v1.39.0 github.com/stretchr/testify v1.9.0 + golang.org/x/term v0.15.0 ) require ( diff --git a/go.sum b/go.sum index e2aa275..d5b72da 100644 --- a/go.sum +++ b/go.sum @@ -323,6 +323,7 @@ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuX golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= +golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= diff --git a/main.go b/main.go index 81750c1..716339f 100644 --- a/main.go +++ b/main.go @@ -14,7 +14,7 @@ import ( "syscall" "time" - "github.com/samber/lo" + "golang.org/x/term" ) var ( @@ -169,9 +169,9 @@ func run(ctx context.Context, name string, args, env []string, l *slog.Logger) i cmd.Stdin = os.Stdin cmd.Stderr = os.Stderr cmd.Stdout = os.Stdout - if !lo.Contains([]string{"sh", "bash", "zsh", "fish"}, name) { - cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true} - } + + isTerm := term.IsTerminal(int(os.Stdin.Fd())) + cmd.SysProcAttr = &syscall.SysProcAttr{Foreground: isTerm, Setsid: !isTerm} if err := cmd.Start(); err != nil { l.ErrorContext(ctx, "Could not start command", "error", err, "cmd", cmd.String()) @@ -187,8 +187,7 @@ func run(ctx context.Context, name string, args, env []string, l *slog.Logger) i // forward signals to the child process go func() { - for { - s := <-sigch + for s := range sigch { if s == syscall.SIGCHLD { continue }