From 84eaef0bbb405b9401c9820ae3d006daedba7e43 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 23 Dec 2022 12:36:31 -0800 Subject: [PATCH] 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 --- ssh/tailssh/incubator.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ssh/tailssh/incubator.go b/ssh/tailssh/incubator.go index 5c975046b..c3e865630 100644 --- a/ssh/tailssh/incubator.go +++ b/ssh/tailssh/incubator.go @@ -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.