Skip to content

Commit

Permalink
Remove "runtime" hidden feature of rustix, replace with safe-fork
Browse files Browse the repository at this point in the history
  • Loading branch information
nbdd0121 committed Oct 7, 2024
1 parent 3e52a32 commit c381706
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ tokio = { version = "1", features = ["full"] }
tokio-stream = "0.1"
async-stream = "0.3"
udev = "0.8"
rustix = { version = "0.38", features = ["fs", "stdio", "process", "thread", "runtime", "pipe"] }
rustix = { version = "0.38", features = ["fs", "stdio", "process", "thread", "pipe"] }
bitflags = "2"
once_cell = "1"
humantime = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
safe-fork = "0.1.1"
aya = { git = "https://github.com/aya-rs/aya.git" }

[build-dependencies]
Expand Down
16 changes: 5 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ use runc::cli::{CreateOptions, GlobalOptions};
use runc::Container;
use rustix::fd::OwnedFd;
use rustix::pipe::PipeFlags;
use rustix::process::{Signal, WaitOptions};
use rustix::runtime::Fork;
use rustix::process::Signal;
use tokio_stream::StreamExt;

#[derive(Clone)]
Expand Down Expand Up @@ -225,21 +224,16 @@ fn do_main() -> Result<()> {
// or the child process closing it.
let (parent, child) = rustix::pipe::pipe_with(PipeFlags::CLOEXEC)?;
// SAFETY: forking is safe because we are single-threaded now.
match unsafe { rustix::runtime::fork()? } {
Fork::Child(_) => {
match safe_fork::fork()? {
None => {
drop(parent);
tokio::runtime::Runtime::new()?.block_on(create(args.global, create_options, child))?;
}
Fork::Parent(pid) => {
Some(pid) => {
drop(child);
if rustix::io::read(parent, &mut [0])? == 0 {
// In this case, the child process exited before notifying us.
std::process::exit(
rustix::process::waitpid(Some(pid), WaitOptions::empty())?
.unwrap()
.exit_status()
.unwrap_or(1) as _,
);
std::process::exit(pid.join()?.code().unwrap_or(1) as _);
}
}
}
Expand Down

0 comments on commit c381706

Please sign in to comment.