Skip to content

Commit 8fa3f89

Browse files
committed
fix(probe): classify a missing user session bus as absent
systemctl --user show exits 1 with 'Failed to get D-Bus connection: No such file or directory' on hosts that ship systemctl but run no user session bus (WSL, containers, systemd-less distros). The probe mapped every non-zero status to unknown, so ownership inspection reported 'could not be proven' and admission refused every sync/write on such hosts indefinitely (#1939). The two systemd-impossible messages (missing session-bus socket, and WSL's not-booted-with-systemd) now classify as absent — the same conclusion as systemctl being missing, since no user unit can be registered without a user manager. Other bus failures stay unknown: the user manager may genuinely be running with a misconfigured DBUS_SESSION_BUS_ADDRESS, and the existing pinned test for that case is unchanged.
1 parent e97fb26 commit 8fa3f89

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

‎src/service-manager-probe.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,21 @@ function inspectSystemd(deps: Required<Pick<ProbeDeps, "run" | "home">>): Servic
267267
if (shown.spawnFailed) return { kind: "absent" };
268268
if (shown.timedOut) return unknown("systemctl could not be asked: timed out");
269269
if (shown.status !== 0) {
270+
const err = shown.stderr.trim();
270271
// A missing unit still exits ZERO and says not-found; a non-zero status means
271-
// the question never reached the bus.
272-
return unknown(`systemctl show exited ${String(shown.status)}: ${shown.stderr.trim()}`);
272+
// the question never reached the bus. Two of those failures mean it never
273+
// could: with no session-bus socket (or no systemd at all, e.g. WSL), no
274+
// user unit can be registered, so there is nothing to conflict with — the
275+
// same conclusion as systemctl being absent (#1939). Other bus failures
276+
// (e.g. a misconfigured DBUS_SESSION_BUS_ADDRESS while the user manager
277+
// runs) stay unknown.
278+
if (
279+
err.includes("Failed to get D-Bus connection: No such file or directory")
280+
|| err.includes("System has not been booted with systemd")
281+
) {
282+
return { kind: "absent" };
283+
}
284+
return unknown(`systemctl show exited ${String(shown.status)}: ${err}`);
273285
}
274286

275287
const loadState = systemdProperty(shown.stdout, "LoadState");

‎tests/codex-service-manager-probe.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,3 +1008,29 @@ describe("ownership refuses what it cannot prove", () => {
10081008
expect(result.ownership).toBe("owned");
10091009
});
10101010
});
1011+
1012+
describe("systemd probe: no user session bus", () => {
1013+
test("a missing session-bus socket means no user units can exist — absent (#1939)", () => {
1014+
const { run } = recorder(() => ({
1015+
status: 1,
1016+
stderr: "Failed to get D-Bus connection: No such file or directory",
1017+
}));
1018+
expect(inspectServiceManagerInstallation({ run, platform: "linux", home }).kind).toBe("absent");
1019+
});
1020+
1021+
test("WSL's not-booted-with-systemd message is absent for the same reason (#1939)", () => {
1022+
const { run } = recorder(() => ({
1023+
status: 1,
1024+
stderr: "System has not been booted with systemd as init system (PID 1).",
1025+
}));
1026+
expect(inspectServiceManagerInstallation({ run, platform: "linux", home }).kind).toBe("absent");
1027+
});
1028+
1029+
test("other bus failures stay unknown — the user manager may be running", () => {
1030+
const { run } = recorder(() => ({
1031+
status: 1,
1032+
stderr: "Failed to connect to bus: $DBUS_SESSION_BUS_ADDRESS not set",
1033+
}));
1034+
expect(inspectServiceManagerInstallation({ run, platform: "linux", home }).kind).toBe("unknown");
1035+
});
1036+
});

0 commit comments

Comments
 (0)