Documentation
¶
Overview ¶
Package lock implements a cross-platform exclusive file lock primitive used by the bus daemon to enforce the "single bus per ClientID" invariant (plan invariant #3). The primitive is intentionally tiny — it acquires and releases a non-blocking exclusive lock on an opened file handle, with no knowledge of PID files or business semantics. Higher layers (bus/lockfile.go) combine this primitive with PID content read/write to provide the full single-file bus.lock design.
Unix: syscall.Flock(LOCK_EX|LOCK_NB). Windows: windows.LockFileEx with LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrBusy = errors.New("lock: file is held by another process")
ErrBusy indicates the lock is currently held by another process. Callers distinguish "actually busy" (another live bus) from "lock file inaccessible" (FS error) by checking for this sentinel.
Functions ¶
This section is empty.
Types ¶
type File ¶
type File struct {
// contains filtered or unexported fields
}
File represents a held exclusive file lock. Close releases the lock and closes the underlying file handle. A zero File is not usable.
func TryAcquire ¶
TryAcquire opens path (creating it if absent, mode 0600) and attempts to take an exclusive non-blocking lock. Returns ErrBusy when the lock is held by another process; any other error wraps the underlying I/O failure.
The directory containing path must already exist; callers should mkdir with pkg/config.DirPerm beforehand.
func (*File) Close ¶
Close releases the lock and closes the file handle. Safe to call on a nil receiver. Subsequent calls are no-ops.