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
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
Skip pidfd testing on unsupported linux kernel
Only Linux kernel >= 5.10 support pidfd

Signed-off-by: Jiahao XU <[email protected]>
  • Loading branch information
NobodyXu committed Dec 31, 2023
commit 80a1cd716e2e83a1881b97cbccf0cf74894c03fe
29 changes: 28 additions & 1 deletion tokio/src/process/unix/pidfd_reaper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ where
mod test {
use super::*;
use crate::runtime::{Builder as RuntimeBuilder, Runtime};
use std::process::Command;
use std::process::{Command, Output};

fn create_runtime() -> Runtime {
RuntimeBuilder::new_current_thread()
Expand All @@ -190,8 +190,25 @@ mod test {
create_runtime().block_on(fut)
}

fn is_pidfd_available() -> bool {
let Output { stdout, status, .. } = Command::new("uname").arg("-r").output().unwrap();
assert!(status.success());
let stdout = String::from_utf8_lossy(&stdout);

let mut kernel_version_iter = stdout.split_once('-').unwrap().0.split('.');
let major = kernel_version_iter.next().unwrap();
let minor = kernel_version_iter.next().unwrap();

major >= 6 || (major == 5 && minor >= 10)
}

#[test]
fn test_pidfd_reaper_poll() {
if !is_pidfd_available() {
eprintln!("pidfd is not available on this linux kernel, skip this test");
return;
}

run_test(async {
let child = Command::new("true").spawn().unwrap();
let pidfd_reaper = PidfdReaper::new(child).unwrap();
Expand All @@ -203,6 +220,11 @@ mod test {

#[test]
fn test_pidfd_reaper_kill() {
if !is_pidfd_available() {
eprintln!("pidfd is not available on this linux kernel, skip this test");
return;
}

run_test(async {
let child = Command::new("sleep").arg("1800").spawn().unwrap();
let mut pidfd_reaper = PidfdReaper::new(child).unwrap();
Expand All @@ -216,6 +238,11 @@ mod test {

#[test]
fn test_pidfd_reaper_drop() {
if !is_pidfd_available() {
eprintln!("pidfd is not available on this linux kernel, skip this test");
return;
}

run_test(async {
let child = Command::new("true").spawn().unwrap();
let _pidfd_reaper = PidfdReaper::new(child).unwrap();
Expand Down