Parcourir la source

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 <[email protected]>
Brad Fitzpatrick il y a 3 ans
Parent
commit
84eaef0bbb
1 fichiers modifiés avec 14 ajouts et 1 suppressions
  1. 14 1
      ssh/tailssh/incubator.go

+ 14 - 1
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.