Skip to content

Commit 323e098

Browse files
committed
temporal: try fix musl, return old code
1 parent 3951e34 commit 323e098

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/unix.rs

+32
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,39 @@ impl Client {
5555

5656
unsafe fn mk() -> io::Result<(Client, String)> {
5757
let mut pipes = [0; 2];
58+
59+
// Attempt atomically-create-with-cloexec if we can on Linux,
60+
// detected by using the `syscall` function in `libc` to try to work
61+
// with as many kernels/glibc implementations as possible.
62+
#[cfg(target_os = "linux")]
63+
{
64+
use std::sync::atomic::{AtomicBool, Ordering};
65+
66+
static PIPE_AVAILABLE: AtomicBool = AtomicBool::new(true);
67+
if PIPE_AVAILABLE.load(Ordering::SeqCst) {
68+
match libc::syscall(libc::SYS_pipe, pipes.as_mut_ptr()) {
69+
-1 => {
70+
let err = io::Error::last_os_error();
71+
if err.raw_os_error() == Some(libc::ENOSYS) {
72+
PIPE_AVAILABLE.store(false, Ordering::SeqCst);
73+
} else {
74+
return Err(err);
75+
}
76+
}
77+
_ => {
78+
let string_arg = format!(
79+
"--jobserver-fds={},{}",
80+
pipes[0].as_raw_fd(),
81+
pipes[1].as_raw_fd()
82+
);
83+
return Ok((Client::from_fds(pipes[0], pipes[1]), string_arg));
84+
}
85+
}
86+
}
87+
}
88+
5889
cvt(libc::pipe(pipes.as_mut_ptr()))?;
90+
5991
let string_arg = format!(
6092
"--jobserver-fds={},{}",
6193
pipes[0].as_raw_fd(),

0 commit comments

Comments
 (0)