What monit 5.35.2's source needs, and why fork is not needed here
An appendix of milestone 905
(monit is packaged in basalt, installed with jig, and restarts a nife service it watches), written
2026-10-12 (UTC). It is a separate file because the block would otherwise pass §212 (a prose
budget)'s cap.
What monit needs
Read from the monit 5.35.2 release tarball (mmonit.com/monit/dist/, the newest on 2026-10-12 UTC).
- Process statistics go through a per-OS layer,
src/process/sysdep_<OS>.c, eight functions behindprocess_sysdep.h, frominit_processtree_sysdeptoSysdep_getMainThread. A twin layer,src/device/sysdep_<OS>.c, does filesystems. Both exist for AIX, Darwin, DragonFly, FreeBSD, Linux, NetBSD, OpenBSD and Solaris, plus anUNKNOWNstub. - Linux's layer reads
/proc:glob("/proc/[0-9]*"), then per processstat,status,cmdlineand the rest; system-wide/proc/meminfo,/proc/statand/proc/loadavg; mounts from/proc/self/mountsand usage fromstatvfs. - Porting is by adding a layer.
configure.ac(and libmonit's) switch on the build host'sunameand compilesysdep_@ARCH@.c; anything unrecognized warns "Architecture not supported" and getsUNKNOWN. No porting document ships, but a new pair ofsysdepfiles plus aunamecase in twoconfigure.acfiles is the shape the tree is built for.UNKNOWNalone is not enough: itsSysdep_getMainThreadreturns 0, so every pidfile check reads as "not running". - Starting a program:
libmonit/src/system/Command.c'sCommand_executecalls plainfork, thensetsid,dup2, closes descriptors to 256,setgid/setgroups/setuid,umaskandexecve, with no shell. A comment above it rejectsposix_spawnby name (below). Exit status is collected only by aSIGCHLDhandler that loopswaitpid;Process_exitStatussays "Trust SIGCHLD handler to set status". - Existence: a pidfile read by
Util_getPid, or a regex over every command line; thengetpgidandSysdep_getMainThread. - Signals:
SIGTERMstops,SIGHUPreloads,SIGUSR1wakes;monit reloadandmonit quitsignal the daemon found by pidfile.monit status,summaryand the start and stop actions are HTTP requests to the daemon's own web server, over TCP tolocalhostor a Unix socket.daemonizeforks twice;-Iruns in the foreground. - Threads: pthreads are required. One thread runs the web server, one request at a time over
poll; one sends heartbeats to M/Monit. Nothing else. - Sockets: listening TCP and Unix sockets,
getaddrinfo,poll(neverselect),getifaddrs, raw ICMP forping, SMTP for alerts, and 36 protocol tests insrc/protocols/. - Files:
stat(the control file must be owned bygeteuid()), bundled MD5 and SHA-1,regcomp,syslog,getpwnam,crypt,glob. - Build: autotools, libmonit as a configured subdirectory. OpenSSL, PAM and zlib are on by default,
each turned off by a
--without-flag.
Why upstream's objections to posix_spawn do not hold on nife
The comment above Command_execute (libmonit/src/system/Command.c, lines 838 to 871) gives six
reasons for fork. Each assumes a Unix child that inherits its parent's state and must shed it.
A nife child inherits nothing it is not handed, so each step fork exists to run has nothing to do.
setsid, to leave the controlling terminal. A child holds a terminal only if spawn grants one; there is no session to leave.setsidanswersEPERMinc_librarytoday.setuidandsetgid. nife has no users:geteuidisNOBODY. Authority is the capabilities the spawn request grants, so changing privilege means granting less, whichposix_spawncan say.- Closing every descriptor. A child's capability table starts empty apart from its grants, so close-all is the default rather than a step.
chdir. A process stands in the directory it was granted, andchdiranswersENOSYS. The service's directory is a grant in the spawn request: the file actions of milestone 838 (a C library:posix_spawn, and no fork).umask. It is C-library state with no kernel counterpart;c_libraryanswers0o022and enforces no mask. The child starts with its own.- The
cloneandvforklimits. No code runs in a nife child before its image starts. Spawn is a request to the spawner, under §219 (how the shell names an installed program to the spawner). Milestone 172 (a capability-native subprocess primitive) builds the child from an image. Thegetpwuidandgetgrouplistcalls the comment worries about have no users to look up.