fix(daemon): honor launchd running state without pid

This commit is contained in:
Peter Steinberger
2026-04-10 21:30:07 +01:00
parent 1f80ebf643
commit f3c143f0cd
2 changed files with 21 additions and 1 deletions

View File

@@ -554,6 +554,23 @@ describe("launchd install", () => {
expect(output).toContain("did not fully stop the service");
});
it("treats launchctl print state=running as running even when pid is missing", async () => {
const env = createDefaultLaunchdEnv();
const stdout = new PassThrough();
let output = "";
state.stopLeavesRunning = true;
state.printOutput = "state = running\n";
stdout.on("data", (chunk: Buffer) => {
output += chunk.toString();
});
await stopLaunchAgent({ env, stdout });
expect(state.launchctlCalls.some((call) => call[0] === "bootout")).toBe(true);
expect(output).toContain("Stopped LaunchAgent (degraded)");
expect(output).toContain("did not fully stop the service");
});
it("falls back to bootout when launchctl stop itself errors", async () => {
const env = createDefaultLaunchdEnv();
const stdout = new PassThrough();

View File

@@ -519,7 +519,10 @@ async function probeLaunchAgentState(serviceTarget: string): Promise<LaunchAgent
};
}
const runtime = parseLaunchctlPrint(probe.stdout || probe.stderr || "");
if (typeof runtime.pid === "number" && runtime.pid > 1) {
if (
normalizeLowercaseStringOrEmpty(runtime.state) === "running" ||
(typeof runtime.pid === "number" && runtime.pid > 1)
) {
return { state: "running" };
}
return { state: "stopped" };