mirror of
https://github.com/wez/wezterm.git
synced 2024-08-17 10:10:23 +03:00
use pipe2() for atomic cloexec on linux
This commit is contained in:
parent
c0f4e4907d
commit
32389ee980
@ -150,6 +150,27 @@ impl FileDescriptor {
|
||||
}
|
||||
|
||||
impl Pipe {
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn new() -> Fallible<Pipe> {
|
||||
let mut fds = [-1i32; 2];
|
||||
let res = unsafe { libc::pipe2(fds.as_mut_ptr(), libc::O_CLOEXEC) };
|
||||
if res == -1 {
|
||||
bail!(
|
||||
"failed to create a pipe: {:?}",
|
||||
std::io::Error::last_os_error()
|
||||
)
|
||||
} else {
|
||||
let read = FileDescriptor {
|
||||
handle: OwnedHandle { handle: fds[0] },
|
||||
};
|
||||
let write = FileDescriptor {
|
||||
handle: OwnedHandle { handle: fds[1] },
|
||||
};
|
||||
Ok(Pipe { read, write })
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
pub fn new() -> Fallible<Pipe> {
|
||||
let mut fds = [-1i32; 2];
|
||||
let res = unsafe { libc::pipe(fds.as_mut_ptr()) };
|
||||
|
Loading…
Reference in New Issue
Block a user