mirror of
https://github.com/9prodhi/camoufox-rs.git
synced 2026-12-04 08:00:56 +00:00
A freshly written executable can briefly fail to spawn with "Text file busy" when a concurrent fork still holds a writable descriptor. Spawning an external subcommand now retries that error up to five times with a short backoff; other spawn errors are reported immediately. Test fixtures write executables from a helper process so parallel tests no longer race, and process assertions include stderr. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
28 lines
919 B
Rust
28 lines
919 B
Rust
//! Executable fixtures whose writable descriptors stay outside the test process.
|
|
|
|
use std::os::unix::fs::PermissionsExt;
|
|
use std::path::Path;
|
|
use std::process::Command;
|
|
|
|
/// Write in a child so concurrent forks cannot inherit a writable script fd.
|
|
/// Waiting for the writer also guarantees its descriptors close before execution.
|
|
pub(crate) fn write_script(path: &Path, contents: &str, mode: u32) {
|
|
let output = Command::new("/bin/sh")
|
|
.args([
|
|
"-c",
|
|
"printf '%s' \"$1\" > \"$2\"",
|
|
"write-script",
|
|
contents,
|
|
])
|
|
.arg(path)
|
|
.output()
|
|
.expect("run script writer");
|
|
assert!(
|
|
output.status.success(),
|
|
"script writer failed; stderr: {}",
|
|
String::from_utf8_lossy(&output.stderr)
|
|
);
|
|
std::fs::set_permissions(path, std::fs::Permissions::from_mode(mode))
|
|
.expect("set script permissions");
|
|
}
|