Skip to content

libobs: Create Linux process pipes atomically close-on-exec - #493

Closed
ProtonDev-sys wants to merge 3 commits into
obs-rust:masterfrom
ProtonDev-sys:fix/266-linux-pipe-cloexec
Closed

ProtonDev-sys wants to merge 3 commits into
obs-rust:masterfrom
ProtonDev-sys:fix/266-linux-pipe-cloexec

Conversation

@ProtonDev-sys

Copy link
Copy Markdown
Contributor

Refs #266

What and why

Create both Linux process pipes with pipe2(O_CLOEXEC) so another thread cannot exec a child between pipe creation and a later fcntl call. Keep the existing pipe/fcntl path on other platforms and preserve error cleanup.

Add a deterministic regression around the real pipe-posix.c: execute a child immediately after each pipe syscall and check whether it inherits either pipe end. Also check stdin delivery, stdout/stderr capture, and exit status.

RED → GREEN

  • RED commit: 137f0059b7241a66f60668827315a23b6a3d847c. The branch author reports both read/write cases fail, with eight inherited pipe ends across four exec probes.
  • GREEN commit: 2c144b88f97f60b19913c4d470d4a1a8e3042133. The branch author reports both cases pass, including 100 repeats and ASan/UBSan/LSan; removing O_CLOEXEC makes both fail again.
  • These results are recorded in the commits; the submitting agent has inspected the diff but has not rerun the tests.

Remaining validation

Draft: the branch author states full OBS gates were unavailable. The required local gate/attestation is not present in the pushed commit. The concurrent-spawn parity test requested in the issue also remains unverified. This change covers Linux only; other platforms retain their existing behavior.

Checklist

  • Base is master
  • No one else has an open PR for this issue at submission time
  • RED then GREEN commits
  • Local gate passed and the pushed head is stamped
  • Requested concurrent-spawn parity reproduction checked

AI assistance: branch commits credit gpt-6-astra-pro; Codex inspected and submitted the existing branch on the account owner's request.

@zackees

zackees commented Oct 15, 2026

Copy link
Copy Markdown
Member

Maintainer rebase onto master, replacing head 2c144b88f.

  • Conflict: master has since made os_process_pipe_create_internal static. I kept that, and added create_pipe() above it; the test doesn't call the internal function.
  • Formatting: I applied clang-format to test_pipe_cloexec.c, which was the earlier Format and Rust Tests failure.

RED → GREEN (rust/tools/linux-validate/run.sh, verified locally)

  • RED (master's pipe-posix.c with this test): test_pipe_cloexec FAILED (230/231).
  • GREEN: 231/231 OFF and ON, exported symbols IDENTICAL (1766). ./lint is ok.

Still a draft; @ProtonDev-sys, mark it ready when you're happy with it.

@zackees

zackees commented Oct 15, 2026

Copy link
Copy Markdown
Member

CI triage: the only failure is "Rust Tier 2 macos-26", and it is a runner/SDK problem, not your change: the Xcode link of libobs fails with MacOSX27.0.sdk/usr/lib/libSystem.B.tbd: error: unknown architecture. Master fixed this in #808 ("Keep macOS Rust links on the selected SDK"). Fix: rebase onto origin/master (git fetch origin && git rebase --autostash origin/master) and push; CI will rerun. Nothing to change in your code for this. Local check: ./lint and ./unittest (Linux; macOS is CI-only).

@zackees

zackees commented Oct 16, 2026

Copy link
Copy Markdown
Member

The red Rust Tier 2 macos-26 here is not from this change: the ON link fails with MacOSX27.0.sdk/usr/lib/libSystem.B.tbd: error: unknown architecture, which master fixed in #808 (keep macOS Rust links on the selected SDK). Rebasing onto current master (git fetch origin && git rebase origin/master) should clear it.

@zackees

zackees commented Oct 16, 2026

Copy link
Copy Markdown
Member

Status for @ProtonDev-sys, from a read of the diff and the checks.

Review. The change looks correct. On Linux both pipes are made with pipe2(O_CLOEXEC), the later fcntl calls are compiled out there, and the other platforms keep the old path. Error cleanup is unchanged. _GNU_SOURCE is defined only on Linux and only if it is not already set. The RED test (test_pipe_cloexec) execs a child right after each pipe syscall and checks whether it inherited either end, so it fails for the right reason. Per the earlier maintainer comment, it failed against master's pipe-posix.c (230/231) and passed with the fix (231/231 with Rust libobs OFF and ON).

Why it is BLOCKED. One check fails: Rust Tier 2 macos-26. The log shows MacOSX27.0.sdk/.../libSystem.B.tbd: error: unknown architecture while linking libobs. That is the runner SDK problem fixed on master in #808. This head does not contain #808; it is 115 commits behind master. A re-run would hit the same error, so I did not re-run it. All the Linux and Windows jobs and the format checks pass. The merge gate (CI Gate) is red only because of that one job. The PR is also still a draft.

Next steps

  1. Rebase onto current master and push: git fetch origin && git rebase --autostash origin/master. If you would rather I did it, say so here. The previous rebase was done by a maintainer.
  2. Optional: run ./lint and ./unittest, then the local gate (see AGENTS.md), so CI can skip the Linux unit-test jobs. Without the stamp, PR CI runs the full suite, which is fine.
  3. Once CI is green after the rebase, mark the PR ready for review. Edit the checklist in the description to match: the concurrent-spawn parity check is still unchecked, and it is fine to say so there. I will not merge it while it is a draft.

ProtonDev-sys and others added 3 commits October 16, 2026 05:00
Exec a child after each real pipe syscall, before OBS can set CLOEXEC.
Both read and write cases fail: four probes inherit eight pipe ends.
Also check stdin delivery, stdout/stderr capture and exit status.

Refs obs-rust#266.
AI assistance: gpt-6-astra-pro.
Use pipe2(O_CLOEXEC) for both process pipes on Linux. Keep the existing
non-Linux path and error cleanup unchanged.

Both regression cases pass, including 100 repeats and ASan/UBSan/LSan.
Removing O_CLOEXEC makes both cases fail again. Full OBS gates were not
available in the isolated validation environment.

Refs obs-rust#266.
AI assistance: gpt-6-astra-pro.
@zackees

zackees commented Oct 16, 2026

Copy link
Copy Markdown
Member

Rebased onto master (004ae90) so CI picks up #808, the macOS SDK link fix that made Rust Tier 2 macos-26 fail here. Same three commits (RED, GREEN, clang-format), and the rebase had no conflicts. libobs/util/pipe-posix.c is still at the same path after the #1069 host refactor. clang-format and ci/platform_ifdef_ratchet.py pass. Once CI is green, please mark this ready for review.

@zackees

zackees commented Oct 23, 2026

Copy link
Copy Markdown
Member

#266 is closed: the shipped (hybrid) libobs now uses the Rust pipe port, whose std::process pipes are atomic close-on-exec, and pipe-posix.c.h only builds into the C reference/oracle, which keeps upstream behaviour. Unless you want the C reference changed too, this draft can be closed.

@obs-rust-project-manager obs-rust-project-manager Bot moved this to In progress in obs-rust Multiview Oct 25, 2026
@obs-rust-project-manager obs-rust-project-manager Bot moved this from In progress to Needs fix in obs-rust Multiview Oct 25, 2026
@zackees

zackees commented Oct 26, 2026

Copy link
Copy Markdown
Member

Closing as stalled: no reply in 3 days to the note above. The shipped hybrid libobs already creates pipes close-on-exec through the Rust port (#266), and pipe-posix.c.h only builds into the C reference. Reopen if you want the C reference changed too.

@zackees zackees closed this Oct 26, 2026
@obs-rust-project-manager obs-rust-project-manager Bot moved this from Needs fix to Done in obs-rust Multiview Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants