From 1615b1754f6944fbd79bb933adff82d2e9e9319e Mon Sep 17 00:00:00 2001 From: zahash Date: Tue, 23 Jul 2024 17:27:29 +0530 Subject: [PATCH] initial progress on supporting OwnedFd (#2809) --- crates/libcontainer/src/channel.rs | 2 -- crates/libcontainer/src/process/channel.rs | 6 ------ .../src/process/container_intermediate_process.rs | 9 ++------- .../src/process/container_main_process.rs | 14 +++++--------- crates/libcontainer/src/process/fork.rs | 2 +- 5 files changed, 8 insertions(+), 25 deletions(-) diff --git a/crates/libcontainer/src/channel.rs b/crates/libcontainer/src/channel.rs index 67be940e..fd2ea6c0 100644 --- a/crates/libcontainer/src/channel.rs +++ b/crates/libcontainer/src/channel.rs @@ -16,13 +16,11 @@ pub enum ChannelError { #[error("channel connection broken")] BrokenChannel, } -#[derive(Clone)] pub struct Receiver { receiver: RawFd, phantom: PhantomData, } -#[derive(Clone)] pub struct Sender { sender: RawFd, phantom: PhantomData, diff --git a/crates/libcontainer/src/process/channel.rs b/crates/libcontainer/src/process/channel.rs index 7d6102be..cd3a7748 100644 --- a/crates/libcontainer/src/process/channel.rs +++ b/crates/libcontainer/src/process/channel.rs @@ -44,7 +44,6 @@ pub fn main_channel() -> Result<(MainSender, MainReceiver), ChannelError> { Ok((MainSender { sender }, MainReceiver { receiver })) } -#[derive(Clone)] pub struct MainSender { sender: Sender, } @@ -97,7 +96,6 @@ impl MainSender { } } -#[derive(Clone)] pub struct MainReceiver { receiver: Receiver, } @@ -209,7 +207,6 @@ pub fn intermediate_channel() -> Result<(IntermediateSender, IntermediateReceive )) } -#[derive(Clone)] pub struct IntermediateSender { sender: Sender, } @@ -229,7 +226,6 @@ impl IntermediateSender { } } -#[derive(Clone)] pub struct IntermediateReceiver { receiver: Receiver, } @@ -266,7 +262,6 @@ pub fn init_channel() -> Result<(InitSender, InitReceiver), ChannelError> { Ok((InitSender { sender }, InitReceiver { receiver })) } -#[derive(Clone)] pub struct InitSender { sender: Sender, } @@ -285,7 +280,6 @@ impl InitSender { } } -#[derive(Clone)] pub struct InitReceiver { receiver: Receiver, } diff --git a/crates/libcontainer/src/process/container_intermediate_process.rs b/crates/libcontainer/src/process/container_intermediate_process.rs index fad2103d..1bee6f3e 100644 --- a/crates/libcontainer/src/process/container_intermediate_process.rs +++ b/crates/libcontainer/src/process/container_intermediate_process.rs @@ -101,12 +101,7 @@ pub fn container_intermediate_process( } let cb: CloneCb = { - let args = args.clone(); - let init_sender = init_sender.clone(); - let inter_sender = inter_sender.clone(); - let mut main_sender = main_sender.clone(); - let mut init_receiver = init_receiver.clone(); - Box::new(move || { + Box::new(|| { if let Err(ret) = prctl::set_name("youki:[2:INIT]") { tracing::error!(?ret, "failed to set name for child process"); return ret; @@ -123,7 +118,7 @@ pub fn container_intermediate_process( tracing::error!(?err, "failed to close sender in the intermediate process"); return -1; } - match container_init_process(&args, &mut main_sender, &mut init_receiver) { + match container_init_process(args, main_sender, init_receiver) { Ok(_) => 0, Err(e) => { tracing::error!("failed to initialize container process: {e}"); diff --git a/crates/libcontainer/src/process/container_main_process.rs b/crates/libcontainer/src/process/container_main_process.rs index 05bc4d48..fd5dfcb1 100644 --- a/crates/libcontainer/src/process/container_main_process.rs +++ b/crates/libcontainer/src/process/container_main_process.rs @@ -39,23 +39,19 @@ pub fn container_main_process(container_args: &ContainerArgs) -> Result<(Pid, bo // cloned process, we have to be deligent about closing any unused channel. // At minimum, we have to close down any unused senders. The corresponding // receivers will be cleaned up once the senders are closed down. - let (main_sender, mut main_receiver) = channel::main_channel()?; - let inter_chan = channel::intermediate_channel()?; - let init_chan = channel::init_channel()?; + let (mut main_sender, mut main_receiver) = channel::main_channel()?; + let mut inter_chan = channel::intermediate_channel()?; + let mut init_chan = channel::init_channel()?; let cb: CloneCb = { - let container_args = container_args.clone(); - let mut main_sender = main_sender.clone(); - let mut inter_chan = inter_chan.clone(); - let mut init_chan = init_chan.clone(); - Box::new(move || { + Box::new(|| { if let Err(ret) = prctl::set_name("youki:[1:INTER]") { tracing::error!(?ret, "failed to set name for child process"); return ret; } match container_intermediate_process::container_intermediate_process( - &container_args, + container_args, &mut inter_chan, &mut init_chan, &mut main_sender, diff --git a/crates/libcontainer/src/process/fork.rs b/crates/libcontainer/src/process/fork.rs index 64143883..7ec2ef7e 100644 --- a/crates/libcontainer/src/process/fork.rs +++ b/crates/libcontainer/src/process/fork.rs @@ -32,7 +32,7 @@ pub enum CloneError { /// pass in a child stack, which is empty. By storing the closure in heap, we /// can then in the new process to re-box the heap memory back to a closure /// correctly. -pub type CloneCb = Box i32>; +pub type CloneCb<'a> = Box i32 + 'a>; // Clone a sibling process that shares the same parent as the calling // process. This is used to launch the container init process so the parent