sys

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sys provides low-level operating system helpers including file locks and Unix domain socket listeners.

Index

Constants

This section is empty.

Variables

View Source
var ErrLocked = errors.New("sys: lock file is already held")

ErrLocked is returned when a requested lock file is already held by another process.

Functions

func AcquireLock

func AcquireLock(lockPath string) (*os.File, error)

AcquireLock opens the file at lockPath (creating its parent directories if necessary) and acquires an exclusive, non-blocking lock. It records the current process id in the lock file so a second process can report who holds it. It returns ErrLocked if the lock is already held.

func AcquireLockWithRetry

func AcquireLockWithRetry(ctx context.Context, lockPath string, timeout, interval time.Duration) (*os.File, error)

AcquireLockWithRetry behaves like AcquireLock but keeps retrying every interval until the lock is acquired, timeout elapses, or ctx is canceled. On timeout it returns ErrLocked. It gives a daemon that is still tearing down (and holding the lock past its socket shutdown) a short window to finish before a replacement gives up.

func ListenUnix

func ListenUnix(ctx context.Context, socketPath string) (net.Listener, error)

ListenUnix creates a Unix domain socket listener at socketPath with 0600 permissions, removing any stale socket file first.

func LockHolderPID

func LockHolderPID(lockPath string) (int, bool)

LockHolderPID reads the process id recorded in the lock file at lockPath. It returns false when the file is missing, unreadable, or does not hold a valid pid.

func ReleaseLock

func ReleaseLock(f *os.File) error

ReleaseLock unlocks and closes f. It is a no-op if f is nil.

func WaitForLockRelease

func WaitForLockRelease(ctx context.Context, lockPath string, timeout, interval time.Duration) error

WaitForLockRelease blocks until the lock at lockPath is free, timeout elapses, or ctx is canceled. Probing never writes to the lock file, so a waiter cannot clobber the pid recorded by the current holder. It returns ErrLocked when the timeout elapses with the lock still held, and passes other lock failures through unchanged.

Types

This section is empty.

Jump to

Keyboard shortcuts

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