syncs, all: move to using Go's new atomic types instead of ours

Fixes #5185

Change-Id: I850dd532559af78c3895e2924f8237ccc328449d
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2022-08-03 21:51:02 -07:00
committed by Brad Fitzpatrick
parent 9bb5a038e5
commit 4950fe60bd
20 changed files with 101 additions and 143 deletions

View File

@@ -14,12 +14,12 @@ import (
"runtime"
"strconv"
"strings"
"sync/atomic"
"syscall"
"time"
"go4.org/mem"
"golang.org/x/sys/unix"
"tailscale.com/syncs"
)
// Reading the sockfiles on Linux is very fast, so we can do it often.
@@ -27,7 +27,7 @@ const pollInterval = 1 * time.Second
var sockfiles = []string{"/proc/net/tcp", "/proc/net/tcp6", "/proc/net/udp", "/proc/net/udp6"}
var sawProcNetPermissionErr syncs.AtomicBool
var sawProcNetPermissionErr atomic.Bool
const (
v6Localhost = "00000000000000000000000001000000:"
@@ -37,7 +37,7 @@ const (
)
func listPorts() (List, error) {
if sawProcNetPermissionErr.Get() {
if sawProcNetPermissionErr.Load() {
return nil, nil
}
var ret []Port
@@ -48,13 +48,13 @@ func listPorts() (List, error) {
// https://developer.android.com/about/versions/10/privacy/changes#proc-net-filesystem
// Ignore it rather than have the system log about our violation.
if runtime.GOOS == "android" && syscall.Access(fname, unix.R_OK) != nil {
sawProcNetPermissionErr.Set(true)
sawProcNetPermissionErr.Store(true)
return nil, nil
}
f, err := os.Open(fname)
if os.IsPermission(err) {
sawProcNetPermissionErr.Set(true)
sawProcNetPermissionErr.Store(true)
return nil, nil
}
if err != nil {