lock

package
v1.0.54 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

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

View Source
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

func TryAcquire(path string) (*File, error)

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

func (l *File) Close() error

Close releases the lock and closes the file handle. Safe to call on a nil receiver. Subsequent calls are no-ops.

func (*File) File

func (l *File) File() *os.File

File returns the underlying *os.File so callers can Read/Write content while holding the lock. The handle MUST NOT be closed by the caller — use Close on the lock File instead.

func (*File) Path

func (l *File) Path() string

Path returns the file path the lock is held on.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL