daemon

package
v0.7.19 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: MIT Imports: 6 Imported by: 1 module, 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Daemonize

func Daemonize(pidFile string) (bool, error)

Daemonize re-executes the current binary as a background process. The parent process exits after the child starts successfully. Returns true if this is the daemon child process, false if parent.

func IsRunning

func IsRunning(pid int) bool

IsRunning checks if a process with the given PID is still running.

func ReadPID

func ReadPID(path string) (int, error)

ReadPID reads a PID from the given file path.

func RemovePID

func RemovePID(path string) error

RemovePID removes the PID file.

func Signal0

func Signal0() os.Signal

Signal0 returns syscall signal 0 for process existence check.

func StatusDaemon

func StatusDaemon(pidFile string) (bool, int, error)

StatusDaemon checks if the daemon is running.

func StopDaemon

func StopDaemon(pidFile string) error

StopDaemon sends SIGTERM to the process in the PID file.

H-9: verify the recorded PID actually belongs to a labyrinth process before signalling. Without this guard, a stale PID file (after crash + PID reuse) or an attacker-planted PID file lets `labyrinth daemon stop` SIGTERM an arbitrary process. We accept either /proc/<pid>/comm containing "labyrinth" or, if /proc is unavailable, a liveness probe via signal 0 (best-effort match — the kill primitive is still bounded because the parent CLI tool runs as the same user as the daemon, but the cmdline check makes accidental kills impossible on Linux).

func WritePID

func WritePID(path string) error

WritePID writes the current process ID to the given file path.

H-9: open with the platform's most-restrictive flags so a pre-planted symlink at the PID-file path cannot redirect this write to an arbitrary target (the historical /var/run TOCTOU). On systems that support it, O_NOFOLLOW prevents traversal of a symlink at the destination; we always truncate explicitly via O_TRUNC. Mode 0640 (was 0644) keeps the file readable by the service group only.

Types

This section is empty.

Jump to

Keyboard shortcuts

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