Skip to content

refactor: one definition of is_pid_running - #37

Merged
Spacefreak18 merged 1 commit into
Spacefreak18:masterfrom
MrDavid5465:converge-pid
Sep 9, 2026
Merged

refactor: one definition of is_pid_running#37
Spacefreak18 merged 1 commit into
Spacefreak18:masterfrom
MrDavid5465:converge-pid

Conversation

@MrDavid5465

Copy link
Copy Markdown
Contributor

Responding to your maintainability point on #35 — you were right, and this is the sharpest instance of it.

is_pid_running existed twice: once in simapi/getpid.c and once in simd/simd.c. Both were the same function. The duplicate resolved only because an executable's own definition wins over the shared library's, even though simd links simapi and includes simapi.h where it is declared.

Two identical copies were survivable. They stopped being so when the function grew a second code path — sandboxed, the pids being tracked belong to the host's namespace where kill(2) cannot reach them, so the lookup routes through the host. That made it a function with two implementations and two locations: a fix had to be applied twice, and nothing would tell you if you only changed one.

simd's copy is removed. The call resolves to the library's, confirmed by the symbols:

libsimapi.so:  T is_pid_running    (defined)
simd:          U is_pid_running    (undefined, resolved from the library)

The surviving copy also takes simd's better ordering — reject a bogus pid before asking the host anything.

Builds and runs clean. This removes one of the two places the sandbox branching had to be maintained; the remaining seams are all single dispatch points rather than duplicated logic.

I'd also suggest testing the sandboxed path in CI, since nothing currently exercises it — the Flatpak job installs and runs the bundle, so asserting simd sees the host's process table rather than the sandbox's four would turn a silent rot into a build failure. Happy to add that separately if you want it.

🤖 Generated with Claude Code

simd carried its own copy of is_pid_running alongside simapi's. Both were
the same function, and simd already links simapi and includes simapi.h where
it is declared -- the duplicate resolved only because an executable's own
definition wins over the shared library's.

That was survivable while the two were identical. It stopped being so when
the function grew a second code path: sandboxed, the pids being tracked
belong to the host's namespace where kill(2) cannot reach them, so the
lookup routes through the host. A fix to that logic had to be made twice, in
two files, and nothing would report it if only one were changed.

simd's copy is removed and the call now resolves to the library's, which
also picks up simd's better ordering -- reject a bogus pid before asking the
host anything.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@Spacefreak18
Spacefreak18 merged commit d52ec8d into Spacefreak18:master Sep 9, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants