From 2e7e2d87ad319a6364916a5da07c1203f3c292e4 Mon Sep 17 00:00:00 2001 From: Marc Hoersken Date: Thu, 23 May 2024 20:24:50 +0200 Subject: [PATCH] Avoid parent process if no log redirection is used Exec the command without forking in case go-runner does not need to perform log output redirection. Signed-off-by: Marc Hoersken --- images/build/go-runner/go-runner.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/images/build/go-runner/go-runner.go b/images/build/go-runner/go-runner.go index 74762b39fc6..62ea8fcc13e 100644 --- a/images/build/go-runner/go-runner.go +++ b/images/build/go-runner/go-runner.go @@ -46,6 +46,7 @@ func configureAndRun() error { var ( outputStream io.Writer = os.Stdout errStream io.Writer = os.Stderr + err error ) args := flag.Args() @@ -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) }