Skip to content

bug: parseLaunchctlPrint accepts PID 0 (inconsistent with systemd parser) #39188

@scoootscooob

Description

@scoootscooob

Bug

parseLaunchctlPrint() in src/daemon/launchd.ts:131 only checks Number.isFinite(pid) before storing the PID, but the equivalent systemd parser at src/daemon/systemd.ts:122 correctly checks Number.isFinite(pid) && pid > 0.

When launchctl print reports pid = 0 (meaning no running process), the launchd parser stores pid: 0 in the result, which is semantically incorrect — PID 0 is the kernel scheduler, never a user-space service.

Inconsistency

// systemd.ts:122 — correct
if (Number.isFinite(pid) && pid > 0) {
  info.mainPid = pid;
}

// launchd.ts:131 — missing pid > 0
if (Number.isFinite(pid)) {
  info.pid = pid;
}

Expected behavior

parseLaunchctlPrint should reject pid <= 0 the same way parseSystemdShowOutput does.

Impact

Low — the downstream readLaunchAgentRuntime at line 191 accidentally handles this because parsed.pid (0) is falsy in the ternary. But exposing pid: 0 to callers is semantically wrong and fragile.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions