tailscale/safesocket/safesocket_ps.go
Brad Fitzpatrick fb420be176 safesocket: don't depend on go-ps on iOS
There's never a tailscaled on iOS. And we can't run child processes to
look for it anyway.

Updates tailscale/corp#20099

Change-Id: Ieb3776f4bb440c4f1c442fdd169bacbe17f23ddb
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2024-10-09 18:35:53 -07:00

35 lines
692 B
Go

// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
//go:build linux || windows || (darwin && !ios) || freebsd
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
}
}