Documentation
¶
Overview ¶
Package lockutil provides cross-process advisory file locks used by cron, daemon, hooks, oauth, and swarm. Locks are held by the kernel for the lifetime of an open file handle, so process exit releases them without a stale-file reclaim protocol. The lock file itself is stable: holders never rename or remove it while another process may still have its inode locked.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrLockHeld reports that another process or goroutine currently holds the // advisory lock. Callers may wait and retry until their own deadline. ErrLockHeld = errors.New("lockutil: lock is held") // ErrLockReleased reports an attempt to update metadata after Release. ErrLockReleased = errors.New("lockutil: lock is released") )
Functions ¶
This section is empty.
Types ¶
type FileLock ¶
type FileLock struct {
// contains filtered or unexported fields
}
FileLock is an exclusive advisory lock held through an open file handle. Release is idempotent. The lock path remains on disk after release; deleting or replacing it would let different processes lock different inodes.
func TryAcquireFileLock ¶
TryAcquireFileLock attempts to take an exclusive advisory lock without waiting. A contended lock returns ErrLockHeld. The kernel releases a lock if its process exits, so an old unlocked file never needs stale reclamation.
func TryAcquireFileLockAt ¶
TryAcquireFileLockAt attempts to lock path while confining every component below root to a handle-relative traversal. root is the caller's trusted boundary and may itself be reached through a legitimate link; links and reparse points below it are rejected before metadata can be written.
func TryAcquireFileLockRoot ¶
TryAcquireFileLockRoot attempts to lock name relative to an already-bound directory root. It is intended for lifecycle owners that must not resolve the root pathname again between validation and lock acquisition.
func (*FileLock) Release ¶
Release unlocks and closes the held file handle. It deliberately leaves the stable lock file in place. Repeated calls return the first release result.
func (*FileLock) WriteMetadata ¶
WriteMetadata replaces the diagnostic contents of the lock file while the caller holds it. Metadata does not establish ownership; the kernel lock does.