2023-01-27 21:37:20 +00:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2021-08-31 21:36:10 +00:00
|
|
|
|
2024-10-10 00:55:42 +00:00
|
|
|
//go:build linux || windows || (darwin && !ios) || freebsd
|
2021-08-31 21:36:10 +00:00
|
|
|
|
|
|
|
package safesocket
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
ps "github.com/mitchellh/go-ps"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
tailscaledProcExists = func() bool {
|
|
|
|
procs, err := ps.Processes()
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
for _, proc := range procs {
|
|
|
|
name := proc.Executable()
|
|
|
|
const tailscaled = "tailscaled"
|
|
|
|
if len(name) < len(tailscaled) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
// Do case insensitive comparison for Windows,
|
|
|
|
// notably, and ignore any ".exe" suffix.
|
|
|
|
if strings.EqualFold(name[:len(tailscaled)], tailscaled) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|