//! Serializes pipe creation and fork while close-on-exec is set separately.
use std::io;
use std::sync::Mutex;
static SPAWN: Mutex<()> = Mutex::new(());
pub fn locked<T>(spawn: impl FnOnce() -> io::Result<T>) -> io::Result<T> {
let guard = SPAWN
.lock()
.map_err(|error| io::Error::other(format!("process_spawn_lock_failed: {error}")))?;
let result = spawn();
drop(guard);
result
}