Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(process): Use pidfd on Linux for tokio::process::Child::wait #6152

Merged
merged 17 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Only pull in PidfdReaper if feature rt is enabled on Linux
Instead of automatically enabling feature `rt` if `process` is enabled,
even if the target os is not `linux`.

Signed-off-by: Jiahao XU <[email protected]>
  • Loading branch information
NobodyXu committed Jan 9, 2024
commit bf14726438f79a75cd2d652c6cc99e7ad46d250f
1 change: 0 additions & 1 deletion tokio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ net = [
"windows-sys/Win32_System_SystemServices",
]
process = [
"rt",
"bytes",
"libc",
"mio/os-poll",
Expand Down
12 changes: 6 additions & 6 deletions tokio/src/process/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use orphan::{OrphanQueue, OrphanQueueImpl, Wait};
mod reap;
use reap::Reaper;

#[cfg(target_os = "linux")]
#[cfg(all(target_os = "linux", feature = "rt"))]
mod pidfd_reaper;

use crate::io::{AsyncRead, AsyncWrite, PollEvented, ReadBuf};
Expand Down Expand Up @@ -105,7 +105,7 @@ impl OrphanQueue<StdChild> for GlobalOrphanQueue {
#[must_use = "futures do nothing unless polled"]
pub(crate) enum Child {
SignalReaper(Reaper<StdChild, GlobalOrphanQueue, Signal>),
#[cfg(target_os = "linux")]
#[cfg(all(target_os = "linux", feature = "rt"))]
PidfdReaper(pidfd_reaper::PidfdReaper<StdChild, GlobalOrphanQueue>),
}

Expand All @@ -121,7 +121,7 @@ pub(crate) fn spawn_child(cmd: &mut std::process::Command) -> io::Result<Spawned
let stdout = child.stdout.take().map(stdio).transpose()?;
let stderr = child.stderr.take().map(stdio).transpose()?;

#[cfg(target_os = "linux")]
#[cfg(all(target_os = "linux", feature = "rt"))]
match pidfd_reaper::PidfdReaper::new(child, GlobalOrphanQueue) {
NobodyXu marked this conversation as resolved.
Show resolved Hide resolved
Ok(pidfd_reaper) => {
return Ok(SpawnedChild {
Expand Down Expand Up @@ -149,15 +149,15 @@ impl Child {
pub(crate) fn id(&self) -> u32 {
match self {
Self::SignalReaper(signal_reaper) => signal_reaper.id(),
#[cfg(target_os = "linux")]
#[cfg(all(target_os = "linux", feature = "rt"))]
Self::PidfdReaper(pidfd_reaper) => pidfd_reaper.id(),
}
}

fn std_child(&mut self) -> &mut StdChild {
match self {
Self::SignalReaper(signal_reaper) => signal_reaper.inner_mut(),
#[cfg(target_os = "linux")]
#[cfg(all(target_os = "linux", feature = "rt"))]
Self::PidfdReaper(pidfd_reaper) => pidfd_reaper.inner_mut(),
}
}
Expand All @@ -179,7 +179,7 @@ impl Future for Child {
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
match Pin::into_inner(self) {
Self::SignalReaper(signal_reaper) => Pin::new(signal_reaper).poll(cx),
#[cfg(target_os = "linux")]
#[cfg(all(target_os = "linux", feature = "rt"))]
Self::PidfdReaper(pidfd_reaper) => Pin::new(pidfd_reaper).poll(cx),
}
}
Expand Down
Loading