mirror of
https://github.com/tailscale/tailscale.git
synced 2026-12-05 08:02:20 -08:00
On macOS, the incubator execs /usr/bin/login to run non-interactive commands so that they run in a macOS login session (see #4939). But macOS login runs the program as a child and exits 0 regardless of how it exited, so every command over Tailscale SSH to a Mac reported success to the client: "ssh mac 'exit 7'" exited 0. The same happened to shells without a TTY, such as "ssh -T mac < script". For those sessions, run login as a child instead, telling it to run "tailscaled be-child ssh-login-cmd", which runs the user's shell as login would have (as a login shell, with argv[0] "-zsh") and writes its exit status to a file created by the incubator and owned by the local user. login closes inherited descriptors, so a pipe can't be used. The helper unlinks the file as soon as it starts, and the incubator reads the status through its own descriptor and exits with it, or with login's status (or 1) if none was recorded, so an unknown result is never reported as success. login stays in the incubator's process group, as it did when the incubator exec'd into it, so the ssh-monitor's SIGHUP and SIGKILL to the session's group still reach it and the command. With a TTY that group is the terminal's foreground group, so the incubator ignores the terminal's SIGINT and SIGQUIT while it waits. Interactive shells with a TTY and SFTP still exec into login, and other platforms are unchanged. Also run the SSH integration tests on macOS in CI, as root and as a regular user, and fix the tests that assumed /proc or Linux's stty -a output. Fixes #18256 RELNOTE: Tailscale SSH on macOS now reports the exit status of non-interactive commands instead of always exiting 0. Change-Id: I3fb4f5201667a5a218b996e0d9762429337857eb Signed-off-by: Bazyli Brzoska <[email protected]>