mirror of
https://github.com/tailscale/tailscale.git
synced 2026-05-06 20:56:24 +02:00
I omitted a lot of the min/max modernizers because they didn't result in more clear code. Some of it's older "for x := range 123". Also: errors.AsType, any, fmt.Appendf, etc. Updates #18682 Change-Id: I83a451577f33877f962766a5b65ce86f7696471c Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
37 lines
922 B
Go
37 lines
922 B
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package cli
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
)
|
|
|
|
func findSSH() (string, error) {
|
|
// use C:\Windows\System32\OpenSSH\ssh.exe since unexpected behavior
|
|
// occurred with ssh.exe provided by msys2/cygwin and other environments.
|
|
if systemRoot := os.Getenv("SystemRoot"); systemRoot != "" {
|
|
exe := filepath.Join(systemRoot, "System32", "OpenSSH", "ssh.exe")
|
|
if st, err := os.Stat(exe); err == nil && !st.IsDir() {
|
|
return exe, nil
|
|
}
|
|
}
|
|
return exec.LookPath("ssh")
|
|
}
|
|
|
|
func execSSH(ssh string, argv []string) error {
|
|
// Don't use syscall.Exec on Windows, it's not fully implemented.
|
|
cmd := exec.Command(ssh, argv[1:]...)
|
|
cmd.Stdin = os.Stdin
|
|
cmd.Stdout = os.Stdout
|
|
cmd.Stderr = os.Stderr
|
|
err := cmd.Run()
|
|
if ee, ok := errors.AsType[*exec.ExitError](err); ok {
|
|
os.Exit(ee.ExitCode())
|
|
}
|
|
return err
|
|
}
|