Skip to content

Commit

Permalink
Merge pull request #216 from articulate/fix/foreground-interactive
Browse files Browse the repository at this point in the history
feat: run child process in foreground on interactive
  • Loading branch information
mloberg authored May 20, 2024
2 parents 2e227dc + 35e1eda commit 47db45c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
11 changes: 5 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"syscall"
"time"

"github.com/samber/lo"
"golang.org/x/term"
)

var (
Expand Down Expand Up @@ -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())
Expand All @@ -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
}
Expand Down

0 comments on commit 47db45c

Please sign in to comment.