mirror of
https://github.com/tailscale/tailscale.git
synced 2025-01-09 17:43:40 +00:00
71029cea2d
This updates all source files to use a new standard header for copyright and license declaration. Notably, copyright no longer includes a date, and we now use the standard SPDX-License-Identifier header. This commit was done almost entirely mechanically with perl, and then some minimal manual fixes. Updates #6865 Signed-off-by: Will Norris <will@tailscale.com>
75 lines
2.2 KiB
Go
75 lines
2.2 KiB
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//go:build linux || windows || darwin
|
|
|
|
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"runtime"
|
|
"strings"
|
|
|
|
ps "github.com/mitchellh/go-ps"
|
|
"tailscale.com/version/distro"
|
|
)
|
|
|
|
// fixTailscaledConnectError is called when the local tailscaled has
|
|
// been determined unreachable due to the provided origErr value. It
|
|
// returns either the same error or a better one to help the user
|
|
// understand why tailscaled isn't running for their platform.
|
|
func fixTailscaledConnectError(origErr error) error {
|
|
procs, err := ps.Processes()
|
|
if err != nil {
|
|
return fmt.Errorf("failed to connect to local Tailscaled process and failed to enumerate processes while looking for it")
|
|
}
|
|
var foundProc ps.Process
|
|
for _, proc := range procs {
|
|
base := filepath.Base(proc.Executable())
|
|
if base == "tailscaled" {
|
|
foundProc = proc
|
|
break
|
|
}
|
|
if runtime.GOOS == "darwin" && base == "IPNExtension" {
|
|
foundProc = proc
|
|
break
|
|
}
|
|
if runtime.GOOS == "windows" && strings.EqualFold(base, "tailscaled.exe") {
|
|
foundProc = proc
|
|
break
|
|
}
|
|
}
|
|
if foundProc == nil {
|
|
switch runtime.GOOS {
|
|
case "windows":
|
|
return fmt.Errorf("failed to connect to local tailscaled process; is the Tailscale service running?")
|
|
case "darwin":
|
|
return fmt.Errorf("failed to connect to local Tailscale service; is Tailscale running?")
|
|
case "linux":
|
|
var hint string
|
|
if isSystemdSystem() {
|
|
hint = " (sudo systemctl start tailscaled ?)"
|
|
}
|
|
return fmt.Errorf("failed to connect to local tailscaled; it doesn't appear to be running%s", hint)
|
|
}
|
|
return fmt.Errorf("failed to connect to local tailscaled process; it doesn't appear to be running")
|
|
}
|
|
return fmt.Errorf("failed to connect to local tailscaled (which appears to be running as %v, pid %v). Got error: %w", foundProc.Executable(), foundProc.Pid(), origErr)
|
|
}
|
|
|
|
// isSystemdSystem reports whether the current machine uses systemd
|
|
// and in particular whether the systemctl command is available.
|
|
func isSystemdSystem() bool {
|
|
if runtime.GOOS != "linux" {
|
|
return false
|
|
}
|
|
switch distro.Get() {
|
|
case distro.QNAP, distro.Gokrazy, distro.Synology:
|
|
return false
|
|
}
|
|
_, err := exec.LookPath("systemctl")
|
|
return err == nil
|
|
}
|