From 461ba4de3a9996506682351d127ee9e0eed79fb2 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 6 Aug 2023 18:48:27 -0400 Subject: fix build on macos --- src/sys.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/sys.rs b/src/sys.rs index 878a374..c3d633c 100644 --- a/src/sys.rs +++ b/src/sys.rs @@ -9,13 +9,16 @@ pub struct Pty(std::os::fd::OwnedFd); impl Pty { pub fn open() -> crate::Result { let pt = rustix::pty::openpt( - rustix::pty::OpenptFlags::RDWR - | rustix::pty::OpenptFlags::NOCTTY - | rustix::pty::OpenptFlags::CLOEXEC, + // can't use CLOEXEC here because it's linux-specific + rustix::pty::OpenptFlags::RDWR | rustix::pty::OpenptFlags::NOCTTY, )?; rustix::pty::grantpt(&pt)?; rustix::pty::unlockpt(&pt)?; + let mut flags = rustix::io::fcntl_getfd(&pt)?; + flags |= rustix::io::FdFlags::CLOEXEC; + rustix::io::fcntl_setfd(&pt, flags)?; + Ok(Self(pt)) } @@ -31,7 +34,9 @@ impl Pty { ); if ret == -1 { Err(rustix::io::Errno::from_raw_os_error( - *libc::__errno_location(), + std::io::Error::last_os_error() + .raw_os_error() + .unwrap_or(0), ) .into()) } else { -- cgit v1.2.3-54-g00ecf