Repository navigation
obs-util: Port Linux sleep inhibition to Rust - #1504
Merged
Merged
Conversation
Pins os_inhibit_sleep_* in libobs/util/platform-nix-inhibit.c on Linux and FreeBSD before the Rust port, so the port cannot drop a path the way the first platform-nix port dropped the portal and D-Bus inhibitors. No Rust and no production code change. test_inhibit_sleep (new) covers the path with no session D-Bus: the bus address points at a missing socket and PATH holds only a fake xdg-screensaver, so the user's session is never touched. It pins a NULL inhibitor, set_active returning true only on a change, 50 activate/deactivate cycles, destroy while active joining the thread at once, NULL, empty, long and non-ASCII reasons, and two independent inhibitors. The first reset waits the full 30 s, so the fake never runs. test_inhibit_sleep_dbus gains seven cases on its private bus: the portal is used and the session screensaver is not when both exist, repeated set_active on the portal and on org.freedesktop.ScreenSaver reaches the service once per change, destroy while active releases the inhibit, the reason is copied at create byte for byte, and an empty bus falls back without calling either service. Without dbus-daemon it used to skip every case, which cmocka reports as a pass, so a Tier 2 image without dbus would have passed it silently. It now exits 77 (SKIP_RETURN_CODE), and check-skips.sh refuses a skipped test_inhibit_sleep* in Tier 2. Not pinned: the Flatpak branch (needs /.flatpak-info at the root) and a NULL reason with a portal or D-Bus inhibitor (reaches g_variant_new_string(NULL)). Refs obs-rust#1500
RED for the port of libobs/util/platform-nix-inhibit.c: the safe core's API in obs-util::platform::unix::nix_inhibit with todo!() bodies, and its Tier 1 tests against a host that records every call. The tests port test_inhibit_sleep.c and test_inhibit_sleep_dbus.c case for case (same names), then add what a C test cannot reach: the reset thread without the 30 s wait, a failed spawn, a failed thread start, the Flatpak branch and a build without GIO. soldr cargo test -p obs-util --lib tests::platform::nix_inhibit:: fails 24 of 25 with "not yet implemented"; null_info_is_rejected passes. Refs obs-rust#1500
os_inhibit_sleep_create/_set_active/_destroy on Linux and FreeBSD (libobs/util/platform-nix-inhibit.c) move to obs-util::platform::unix::nix_inhibit, with the C ABI shim in ffi/platform_nix_inhibit.rs. libobs-with-rust links the shim; the C file moves to its own ported group, libobs.ported-nix-inhibit, listed in LIBOBS_LINUX_PORTED_SOURCES. The portal and session D-Bus inhibitors (platform-nix-portal.c, platform-nix-dbus.c) stay C and are called as before, so the port does not lose them the way the first platform-nix port did (obs-rust#453): the portal first, the session inhibitors only without it, nothing in a Flatpak without the portal, otherwise the xdg-screensaver reset thread. GIO_FOUND reaches Rust as the libobs-rust feature gio. os-linux.cmake and os-freebsd.cmake turn off the default features and set gio from find_package(Gio); a plain Cargo build has it on by default. The oracle compiles the original file twice, with and without GIO_FOUND, and routes what it calls outside itself (the inhibitors, the Flatpak check, posix_spawnp, blog and the reset thread's wait) to counted C stand-ins. The Rust core's test host calls the same stand-ins, so the parity test compares returns and calls line for line over random sequences, and the shim against the oracle of the build's GIO setting. Intentional differences: the inhibitor is a Box and the reason a CString; a thread that cannot start returns false (C checks pthread_create < 0, never true); the reset retries its wait only on EINTR (C retries any waitpid error, forever on ECHILD). obs-nix.c, which shared the PCH, now includes <unistd.h> itself. Fixes obs-rust#1500
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked: on #1503 (
test: Characterize Linux sleep inhibition before its port, commit506f04bc2). Review and merge that first. This branch holds its commit too, and the two commits after it are this PR.Fixes #1500
What and why
os_inhibit_sleep_create/_set_active/_destroyon Linux and FreeBSD (libobs/util/platform-nix-inhibit.c.h) move toobs-util::platform::unix::nix_inhibit. The C ABI shim isobs-util/src/ffi/platform_nix_inhibit.rs.libobs-with-rustlinks the shim. The C file moves to its own ported group,libobs.ported-nix-inhibit(with its own PCH), listed inLIBOBS_LINUX_PORTED_SOURCES. The public header is unchanged.The first platform-nix port (#403) dropped the portal and session D-Bus inhibitors (#453), and #454 split this file out to keep them. They stay C here too (
platform-nix-portal.c,platform-nix-dbus.c, grouplibobs.nix-dbus), and the Rust core calls them in the C's order:xdg-screensaver resetthread, every 30 s.GIO_FOUNDreaches Rust as thelibobs-rustfeaturegio(→obs-util/gio).libobs/cmake/os-linux.cmakeandos-freebsd.cmaketurn off the default features and setgiofromfind_package(Gio). Corrosion then runs--no-default-features --features=gio, or--no-default-featureswithout GIO. The feature is on by default for a plain Cargo build. A forgotten flag then keeps the portal path, and a libobs without GIO fails to link instead of losing inhibition silently. Nothing is decided at run time.Intentional differences (also in the parity test header, the core's module docs and
rust/README.md):Boxand the reason aCString. C usesbzallocandbstrdup.set_activereturn false, and the inhibitor stays inactive. C checkspthread_create(...) < 0, which never holds, so it returns true and later joins a thread that does not exist.xdg-screensaveronly when interrupted. C retries anywaitpidfailure, so withSIGCHLDignored (ECHILD) it never stops trying.The child is started with std's
Command: an empty signal mask and defaultSIGPIPE, like the C'sposix_spawnattr_t. The safe core has nounsafe.Other changes:
obs-nix.cshared the old PCH and got<unistd.h>from this file's section, so its section now includes it.platform-nixand its parity test are updated.RED → GREEN
506f04bc2).test_inhibit_sleepandtest_inhibit_sleep_dbusare unchanged here (git diff 506f04bc2 HEAD -- test/ ci/is empty).91c1ffac0obs-util: Fail Linux sleep inhibition on stubs.soldr cargo test -p obs-util --lib tests::platform::nix_inhibit::fails 24 of 25 withnot yet implemented: create.null_info_is_rejectedpasses.c8f63a372. Tier 1: 25/25. They port both C tests case for case, under the same names. They also cover the reset thread without the 30 s wait, a failed spawn, a failed thread start, the Flatpak branch, a build without GIO, and the real spawn and itsENOENT.nix_inhibit_parity):oracle_gio_*and asoracle_*. What the file calls outside itself goes to counted C stand-ins (obs-c-oracle/oracle/nix_inhibit_stubs_posix.c): the inhibitors,access("/.flatpak-info"),posix_spawnp,blog, and the reset thread's wait, which times out on request. The Rust core's test host calls the same stand-ins, and the driver waits for each reset thread to park. Returns and calls are compared line for line, in order.cmocka_sequences_match_oracle: the C tests' step lists, for every mix of GIO, portal, D-Bus and Flatpak.random_sequences_match_oracle: 96 proptest cases of create, set_active (also on NULL), destroy and resets, with random reasons including bytes that are not UTF-8.shim_sequences_match_oracle: 32 cases of the realos_inhibit_sleep_*against the oracle with this build's GIO setting. It passes with and without--features gio.spawncomes beforewait 30000 timeout;flatpak_without_portal_gives_no_inhibitor;shim_sequences_match_oraclewith--features gio.uv run ci/local_gate.py --lane rust-test: ok. 1478 passed, 0 failed; theobs-utillib harness 616/616.--lane lint: ok (clippy-D warnings, rustfmt, dylints, clang-format 22.1.3, gersemi).--lane cross(aarch64-apple-darwin, x86_64-pc-windows-msvc): ok. Clippy-D warningsalso onobs-utilwith and withoutgio.rust/tools/linux-validate/run.sh, which needs Docker and could not run here:test_inhibit_sleeptest_inhibit_sleep_dbusENABLE_RUST_LIBOBS=OFF)libobs(OFF)libobs-with-rust(ON)CMAKE_DISABLE_FIND_PACKAGE_Gio), OFF / ONctest -R '^test_inhibit_sleep' --repeat until-fail:20: passed in all three GIO builds.check-skips.shpasses on all three ctest logs.os_inhibit_sleep_*are the Rust shims and call the hidden Cportal_inhibit_info_createanddbus_sleep_info_create. The build without GIO links no portal or D-Bus code.test_inhibit_sleep_dbusdrives the real libobs entry points against a fake portal and screensaver on a private bus, in both binaries. No UI, protocol or log change.Not checked here: FreeBSD (built by CMake the same way as Linux; no cross lane for it), and the Docker Tier 2 harness, which PR CI runs.
Checklist
master(or the description starts with a Stacked: note)