Skip to content

Commit 93be5c2

Browse files
committed
Replace direct dependency on libc with rustix
1 parent 2a2c1ee commit 93be5c2

File tree

3 files changed

+9
-23
lines changed

3 files changed

+9
-23
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
os: [ubuntu-latest, windows-latest]
4949
# When updating this, the reminder to update the minimum supported
5050
# Rust version in Cargo.toml.
51-
rust: ['1.47']
51+
rust: ['1.48']
5252
steps:
5353
- uses: actions/checkout@v3
5454
- name: Install Rust

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ name = "async-process"
66
version = "1.6.0"
77
authors = ["Stjepan Glavina <[email protected]>"]
88
edition = "2018"
9-
rust-version = "1.47"
9+
rust-version = "1.48"
1010
description = "Async interface for working with processes"
1111
license = "Apache-2.0 OR MIT"
1212
repository = "https://github.com/smol-rs/async-process"
@@ -25,7 +25,7 @@ autocfg = "1"
2525

2626
[target.'cfg(unix)'.dependencies]
2727
async-io = "1.8"
28-
libc = "0.2.88"
28+
rustix = { version = "0.36", default-features = false, features = ["std", "fs"] }
2929

3030
[target.'cfg(unix)'.dependencies.signal-hook]
3131
version = "0.3.0"

src/lib.rs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ impl Child {
170170
(s, r)
171171
}
172172

173-
174173
// Called when a child exits.
175174
unsafe extern "system" fn callback(_: *mut c_void, _: BOOLEAN) {
176175
callback_channel().0.try_send(()).ok();
@@ -485,7 +484,7 @@ impl ChildStdin {
485484
Ok(self.0.into_inner().await.into())
486485
} else if #[cfg(unix)] {
487486
let child_stdin = self.0.into_inner()?;
488-
blocking_fd(child_stdin.as_raw_fd())?;
487+
blocking_fd(rustix::fd::AsFd::as_fd(&child_stdin))?;
489488
Ok(child_stdin.into())
490489
}
491490
}
@@ -577,7 +576,7 @@ impl ChildStdout {
577576
Ok(self.0.into_inner().await.into())
578577
} else if #[cfg(unix)] {
579578
let child_stdout = self.0.into_inner()?;
580-
blocking_fd(child_stdout.as_raw_fd())?;
579+
blocking_fd(rustix::fd::AsFd::as_fd(&child_stdout))?;
581580
Ok(child_stdout.into())
582581
}
583582
}
@@ -650,7 +649,7 @@ impl ChildStderr {
650649
Ok(self.0.into_inner().await.into())
651650
} else if #[cfg(unix)] {
652651
let child_stderr = self.0.into_inner()?;
653-
blocking_fd(child_stderr.as_raw_fd())?;
652+
blocking_fd(rustix::fd::AsFd::as_fd(&child_stderr))?;
654653
Ok(child_stderr.into())
655654
}
656655
}
@@ -1063,22 +1062,9 @@ impl fmt::Debug for Command {
10631062

10641063
/// Moves `Fd` out of non-blocking mode.
10651064
#[cfg(unix)]
1066-
fn blocking_fd(fd: std::os::unix::io::RawFd) -> io::Result<()> {
1067-
// Helper macro to execute a system call that returns an `io::Result`.
1068-
macro_rules! syscall {
1069-
($fn:ident ( $($arg:expr),* $(,)? ) ) => {{
1070-
let res = unsafe { libc::$fn($($arg, )*) };
1071-
if res == -1 {
1072-
return Err(std::io::Error::last_os_error());
1073-
} else {
1074-
res
1075-
}
1076-
}};
1077-
}
1078-
1079-
let res = syscall!(fcntl(fd, libc::F_GETFL));
1080-
syscall!(fcntl(fd, libc::F_SETFL, res & !libc::O_NONBLOCK));
1081-
1065+
fn blocking_fd(fd: rustix::fd::BorrowedFd<'_>) -> io::Result<()> {
1066+
let flags = rustix::fs::fcntl_getfl(fd)?;
1067+
rustix::fs::fcntl_setfl(fd, flags & !rustix::fs::OFlags::NONBLOCK)?;
10821068
Ok(())
10831069
}
10841070

0 commit comments

Comments
 (0)