Files
Privatae e4c9b69b46
ci / personal-data (push) Successful in 5s
ci / test (push) Successful in 3m4s
ci / fuzz (push) Successful in 3m45s
bastion 0.53.2
2026-10-20 04:42:14 +00:00

24 lines
692 B
Go

//go:build !windows
package main
import (
"os"
"golang.org/x/sys/unix"
)
// flockFile takes an exclusive advisory lock on f (blocking). Released by
// closing f. Advisory is enough: every writer of a pairing file is this
// binary, and every one of them goes through withPairingsLock.
func flockFile(f *os.File) error {
return unix.Flock(int(f.Fd()), unix.LOCK_EX)
}
// flockFileNB is flockFile without the wait: it fails immediately when another
// process holds the lock, so an interactive `run` can say "already running"
// instead of hanging as an invisible standby (singleton.go).
func flockFileNB(f *os.File) error {
return unix.Flock(int(f.Fd()), unix.LOCK_EX|unix.LOCK_NB)
}