main: add -F flag to stay in foreground#12
Merged
abonforti merged 1 commit intoazzurra:masterfrom Apr 21, 2026
Merged
Conversation
The fork() at initialize() time detaches services from its launcher and exits the parent, which breaks every process supervisor (docker, systemd with Type=simple, tini, ...) that expects the main process to remain on PID 1 and receive signals directly. With -F set, main() parses the flag before initialize() runs and the fork block in initialize() is skipped; stdin/out/err stay wired to whatever the supervisor attached, and signals land on the services process itself instead of being lost to the gone parent. Everything else (setpgid, pidfile write, signal handlers) runs exactly as before — the only behavioural difference is that services doesn't daemonize. Without -F the old behaviour is preserved bit-for-bit. Build clean: gcc -Wall -Wshadow -Wcast-align -Wsign-compare, 0 warnings.
vjt
added a commit
to vjt/azzurra-testnet
that referenced
this pull request
Apr 20, 2026
azzurra/services main.c unconditionally fork()s and exits the parent in initialize() — under docker the container then sees PID 1 exit and tears the whole stack down. Upstream azzurra/services PR azzurra/services#12 adds a `-F` flag that skips the fork and lets the process run as PID 1. This commit wires it in; the testnet workflow will go green once #12 lands and a new services image is pushed to GHCR.
abonforti
approved these changes
Apr 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
initialize()forks unconditionally at startup and exits the parent, which breaks every supervisor that needs the services process to remain on PID 1:docker run ...— the container exits cleanly (0) the momentRunning in background (pid: N)is printed, because the docker-visible process (the parent) hasexit(EXIT_SUCCESS)'d. The daemonised child keeps running but is an orphan nobody's watching.systemdunits withType=simple— same issue. Either you switch toType=forkingwith aPIDFile=knob (and we writedata/services.pidafter fork, so ordering is racy) or the unit flips betweenactivatingandinactive.tini/dumb-init/ any PID-1 wrapper — defeated for the same reason.This PR adds
-Fto make services skip the fork and run in the foreground. Without-Fbehaviour is bit-for-bit identical to today.What changed
src/main.c— one file, +38/-7.BOOL foreground = FALSE;near the other locals.main(): after the argv[0] path fix, a trivial argv loop that setsforeground = TRUEon-Fand prints a one-line usage for anything else.initialize(): thefork() / exit(EXIT_SUCCESS)block is gated on!foreground. In foreground mode we printRunning in foreground (pid: N)for parity with the old background-pid banner. Everything after (setpgid,write_pidfile, signal handlers, main loop) is untouched.Why this shape
-Fis never passed, the diff is functionally dead code.getopt()pull-in just to handle one flag. Matches the existing ad-hoc style inmain()(the argv[0] / chdir(dirname) block above).Running in background (pid: %d)wording so log scrapers that look for it still work.Test plan
./configure && cd lang && python3 langcomp.py && cd .. && make→gcc -Wall -Wshadow -Wcast-align -Wsign-compare, 0 warnings../services -Finrun/works as before (no fork, startup continues up to the conf-file stage under the caller's tty)../services(no flag) still forks and exits parent immediately, unchanged behaviour.SERVICES_REFin the infra Dockerfile points at a commit that includes this.🤖 Generated with Claude Code