Documentation
¶
Overview ¶
Package platform holds what ncly needs from the operating system: the process tree that cleanup reaches, as Programs that ncly runs in contract.md defines, and the durable writes and the locks of the files in the state folder, as Record format defines.
Index ¶
- Variables
- func BecomeSubreaper() error
- func Descendants(pid int) []int
- func Held(path string) (bool, error)
- func Lock(ctx context.Context, path string, wait time.Duration) (func(), error)
- func MkdirAll(dir string, perm fs.FileMode) error
- func Running(pid int) bool
- func WriteFile(path string, data []byte, perm fs.FileMode) error
Constants ¶
This section is empty.
Variables ¶
var ErrLocked = errors.New("another process holds the lock")
ErrLocked means that another process held a lock for longer than the wait.
Functions ¶
func BecomeSubreaper ¶
func BecomeSubreaper() error
BecomeSubreaper makes this process adopt every orphan among its descendants, so that cleanup still finds a descendant whose parent exited.
func Descendants ¶
Descendants returns the running processes whose chain of parents leads to pid, found through their parent process, so a descendant that left the process group of its parent is still found.
func Held ¶ added in v0.18.0
Held reports whether another process holds the lock file at path. It tries the lock without waiting and without creating the file, and releases it at once, as inspection and dry run in contract.md ask, so it never makes an execution see the lock as held. A missing file is a free lock, because nobody deletes a lock file that someone holds.
func Lock ¶ added in v0.18.0
Lock takes the lock file at path, as Record format in contract.md defines: a file of its own, which Lock creates when it is missing and nobody deletes, because a deleted lock file lets two processes own the lock. It waits at most wait while another process holds the lock, then returns ErrLocked, and it returns the error of ctx, holding nothing, when ctx ends before it takes the lock, even a free one. The returned function releases the lock, and the operating system releases it when the process ends.
func MkdirAll ¶ added in v0.18.0
MkdirAll creates dir and each missing parent, and flushes the parent of each folder that it creates, so a new folder survives a crash, as Record format in contract.md asks of a new state folder.
func Running ¶
Running reports whether a process runs. A zombie, which has exited and waits for its parent to read its status, no longer runs.
func WriteFile ¶ added in v0.18.0
WriteFile replaces the file at path with data durably, as Record format in contract.md writes a record: it writes a temporary file of its own in the same folder, flushes it, renames it over path, then flushes the folder. It creates the folder first, as MkdirAll does. When it fails before the rename, path keeps what it held, and the temporary file is gone.
Types ¶
This section is empty.