ssh/tailssh: don't swallow process exit code in be-child

Thanks to @nshalman and @Soypete for debugging!

Updates #6054

Change-Id: I74550cc31f8a257b37351b8152634c768e1e0a8a
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2022-12-23 12:36:31 -08:00 committed by Brad Fitzpatrick
parent f3c83a06ff
commit 84eaef0bbb
1 changed files with 14 additions and 1 deletions

View File

@ -283,7 +283,20 @@ func beIncubator(args []string) error {
Foreground: true,
}
}
return cmd.Run()
err = cmd.Run()
if ee, ok := err.(*exec.ExitError); ok {
ps := ee.ProcessState
code := ps.ExitCode()
if code < 0 {
// TODO(bradfitz): do we need to also check the syscall.WaitStatus
// and make our process look like it also died by signal/same signal
// as our child process? For now we just do the exit code.
fmt.Fprintf(os.Stderr, "[tailscale-ssh: process died: %v]\n", ps.String())
code = 1 // for now. so we don't exit with negative
}
os.Exit(code)
}
return err
}
// launchProcess launches an incubator process for the provided session.