tool/gocross: ensure child process error codes are propagated on non-Unix

The Unix implementation of doExec propagates error codes by virtue of
the fact that it does an execve; the replacement binary will return the
exit code.

On non-Unix, we need to simulate these semantics by checking for an
ExitError and, when present, passing that value on to os.Exit.

We also add error handling to the doExec call for the benefit of
handling any errors where doExec fails before being able to execute
the desired binary.

Updates https://github.com/tailscale/corp/issues/29940

Signed-off-by: Aaron Klotz <aaron@tailscale.com>
This commit is contained in:
Aaron Klotz
2025-09-15 11:40:34 -06:00
parent 6fb316f5ed
commit 4bb03609bc
2 changed files with 16 additions and 2 deletions
+5 -1
View File
@@ -114,7 +114,11 @@ func main() {
}
doExec(filepath.Join(toolchain, "bin/go"), args, os.Environ())
// Note that doExec only returns if the exec call failed.
if err := doExec(filepath.Join(toolchain, "bin", "go"), args, os.Environ()); err != nil {
fmt.Fprintf(os.Stderr, "executing process: %v\n", err)
os.Exit(1)
}
}
//go:embed gocross-wrapper.sh