FuguLib
FuguLib is the handful of things every OpenBSD daemon needs and the base system does not hand you in Perl: going into the background, writing a PID file, dropping privileges, reaping children, handling signals, and logging to syslog or stderr depending on how you were started.
It is deliberately small. Six modules, no dependencies outside core Perl, no framework, no configuration, and no opinion about what your daemon does. OpenHAP is built on it; nothing in it knows that.
The modules
- FuguLib::Daemon
- Fork,
setsid, redirect the standard descriptors. A callback runs in the parent before it exits, which is where the PID file gets written. - FuguLib::Privdrop
- Drop from root to a named user and group, then verify that root cannot be regained — the check is the point.
- FuguLib::Process
- Spawn, exec, verify a child actually survived start-up, terminate with a
grace period before
SIGKILL, reap zombies, and wait for exit. - FuguLib::Signal
- Register handlers for graceful shutdown or for a flag a long-running loop can poll, with a stack of cleanup callbacks and restoration of the previous handlers.
- FuguLib::Log
- One interface over syslog, stderr and silence, with level filtering and printf-style formatting, so a daemon and a CLI tool can share code.
- FuguLib::State
- PID file reading and writing with locking, plus stale-PID detection built
on
FuguLib::Process.
Reference
Each module has a section 3p manual page, installed with OpenHAP — so
man FuguLib::Daemon works on a machine that has it — and
listed under FuguLib in the manuals.
Name
Fugu is the pufferfish: OpenBSD’s mascot is a pufferfish, and the fish is famously safe only if prepared correctly. Both readings are intended.