Skip to content

Commit

Permalink
fix: Default cmd.Stdin to os.Stdin if nil
Browse files Browse the repository at this point in the history
Signed-off-by: Dana Pieluszczak <[email protected]>
  • Loading branch information
danajp committed Nov 30, 2022
1 parent ddca9cb commit 0834903
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
3 changes: 3 additions & 0 deletions workflow/executor/os-specific/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import (
"os/exec"

"golang.org/x/term"
log "github.com/sirupsen/logrus"
)

var logger = log.WithField("argo", true)

func simpleStart(cmd *exec.Cmd) (func(), error) {
if err := cmd.Start(); err != nil {
return nil, err
Expand Down
13 changes: 9 additions & 4 deletions workflow/executor/os-specific/command_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ import (
)

func StartCommand(cmd *exec.Cmd) (func(), error) {

closer := func() {}

if cmd.Stdin == nil {
cmd.Stdin = os.Stdin
}

cmd.SysProcAttr = &syscall.SysProcAttr{}

if !isTerminal(cmd.Stdin) {
Expand All @@ -34,13 +37,13 @@ func StartCommand(cmd *exec.Cmd) (func(), error) {
stdin, ok := cmd.Stdin.(*os.File)
if !ok {
// should never happen when stdin is a tty
return nil, fmt.Errorf("Cannot convert stdin to os.File")
return nil, fmt.Errorf("Cannot convert stdin to os.File, it was %T", cmd.Stdin)
}

stdout := cmd.Stdout
stderr := cmd.Stderr

// pyt.Start will not assign these to the pty unless they are nil
// pty.Start will not assign these to the pty unless they are nil
cmd.Stdin = nil
cmd.Stdout = nil
cmd.Stderr = nil
Expand All @@ -56,7 +59,9 @@ func StartCommand(cmd *exec.Cmd) (func(), error) {
go func() {
for range sigWinchCh {
// TODO: log error somehow?
_ = pty.InheritSize(stdin, ptmx)
if err := pty.InheritSize(stdin, ptmx); err != nil {
logger.WithError(err).Warn("Cannot resize pty")
}
}
}()

Expand Down
9 changes: 5 additions & 4 deletions workflow/executor/os-specific/command_windows.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package os_specific

import (
"os"
"os/exec"

log "github.com/sirupsen/logrus"
)

var logger = log.WithField("argo", true)

func StartCommand(cmd *exec.Cmd) (func(), error) {
if cmd.Stdin == nil {
cmd.Stdin = os.Stdin
}

if isTerminal(cmd.Stdin) {
logger.Warn("TTY detected but is not supported on windows")
}
Expand Down

0 comments on commit 0834903

Please sign in to comment.