Files
privatae-bastion/client-go/runguard_darwin.go
T
Privatae 8822d5df85
ci / personal-data (push) Successful in 5s
ci / test (push) Successful in 3m51s
ci / fuzz (push) Successful in 2m55s
bastion 0.55.3
2026-10-25 23:16:45 +00:00

35 lines
1.1 KiB
Go

//go:build darwin
package main
import (
"fmt"
"os"
"sync/atomic"
)
// runGuardFile holds the run lock for the life of the process; the kernel
// releases it when the process ends. It is a package-level holder so the
// handle is never collected (a collected *os.File is closed, which would
// release the lock while we are still serving).
var runGuardFile atomic.Pointer[os.File]
// guardSingleRun on macOS: the rule is guardRunBesideService (runlock_unix.go).
// The launchd daemon takes the lock first, so an administrator's `run` beside
// it is refused with a sentence instead of fighting it for the tunnel.
func guardSingleRun() error {
f, err := guardRunBesideService(systemService.installed, configDir, tryRunLock)
if err != nil {
return err
}
runGuardFile.Store(f)
// The daemon, holding the lock, keeps its log in bounds. launchd has no
// size limit of its own for it.
if systemService.installed && processIsRoot() {
if err := keepOneLogAside(darwinDaemonLog, serviceLogCap); err != nil {
fmt.Printf("service: could not set the log aside: %v\n", err)
}
}
return nil
}