Skip to content

Commit

Permalink
Avoid parent process if no log redirection is used
Browse files Browse the repository at this point in the history
Exec the command without forking in case go-runner
does not need to perform log output redirection.

Signed-off-by: Marc Hoersken <[email protected]>
  • Loading branch information
mback2k committed May 23, 2024
1 parent f294861 commit 2e7e2d8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion images/build/go-runner/go-runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func configureAndRun() error {
var (
outputStream io.Writer = os.Stdout
errStream io.Writer = os.Stderr
err error
)

args := flag.Args()
Expand Down Expand Up @@ -79,7 +80,11 @@ func configureAndRun() error {
cmd.Stderr = errStream

log.Printf("Running command:\n%v", cmdInfo(cmd))
err := cmd.Start()
if cmd.Stdout == os.Stdout && cmd.Stderr == os.Stderr {
err = syscall.Exec(cmd.Path, cmd.Args, syscall.Environ())
} else {
err = cmd.Start()
}
if err != nil {
return fmt.Errorf("starting command: %w", err)
}
Expand Down

0 comments on commit 2e7e2d8

Please sign in to comment.