Conversation
detect_init_system() tested for the presence of the `systemctl` binary rather than for systemd running as PID 1. A chroot, a container that pulled systemd in as a dependency, and a half-booted host all have the binary while every systemctl call fails — so the systemd branch of setup_autostart() was chosen on hosts that could not run it. That branch then called `systemctl daemon-reload` and `systemctl enable` with no status check and printed "Auto-start enabled (systemd)" unconditionally, so the user was told autostart was on when nothing had been enabled. The OpenRC branch directly below already verifies and returns 1 with a warning on failure. Gate detection on liveness — /run/systemd/system plus a non-offline `systemctl is-system-running`; note `systemctl --version` exits 0 with no bus at all, so it is not usable as a probe — and check the result of `systemctl enable` before claiming success. Verified: the integration test against a real systemd (PID 1) still passes 14/14, and no test changes result on Debian 12, Alpine 3.20 or Fedora 41.
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.
Problem
detect_init_system()tested for the presence of thesystemctlbinary, not for systemd actually running as PID 1:A chroot, a container that pulled systemd in as a dependency, and a half-booted host all have the binary while every
systemctlcall fails. On those hosts the systemd branch ofsetup_autostart()was selected, then:Both statuses were discarded, so the user was told "Auto-start enabled" when nothing had been enabled. The OpenRC branch directly below already verifies that the runlevel symlink actually landed, and returns 1 with a warning when it did not — the systemd branch did not.
Note
systemctl --versionis not a usable liveness probe either: it exits 0 with no bus at all.Fix
_systemd_is_running()gates detection on liveness:/run/systemd/systemmust exist andsystemctl is-system-runningmust return something other thanoffline. The value is compared rather than the exit status, becausedegradedis still a booted system and exits non-zero.setup_autostart()now checks the result ofsystemctl enablebefore claiming success, and returns 1 with a warning otherwise.Checking
enable's status (rather thanis-enabledoutput) keeps this consistent with the existingsystemctlstubs intests/test_telegram_service_openrc.sh, which model exit statuses rather than stdout.Testing
New
tests/test_init_detection.shdrives asystemctlstub through three scenarios: binary present but not booted (must not be detected as systemd, must not report success), booted butenablefailing (must not report success), and a workingenable(must still report success). The last one guards against over-correcting into always failing.Verified against real systemd — the integration test in the accompanying CI work still passes 14/14 on a container running systemd as PID 1, so the stricter detection does not reject a genuine systemd host.