mirror of
https://github.com/containers/youki
synced 2024-11-26 06:08:07 +01:00
initial progress on supporting OwnedFd (#2809)
This commit is contained in:
parent
cb394e9fc2
commit
1615b1754f
@ -16,13 +16,11 @@ pub enum ChannelError {
|
|||||||
#[error("channel connection broken")]
|
#[error("channel connection broken")]
|
||||||
BrokenChannel,
|
BrokenChannel,
|
||||||
}
|
}
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct Receiver<T> {
|
pub struct Receiver<T> {
|
||||||
receiver: RawFd,
|
receiver: RawFd,
|
||||||
phantom: PhantomData<T>,
|
phantom: PhantomData<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct Sender<T> {
|
pub struct Sender<T> {
|
||||||
sender: RawFd,
|
sender: RawFd,
|
||||||
phantom: PhantomData<T>,
|
phantom: PhantomData<T>,
|
||||||
|
@ -44,7 +44,6 @@ pub fn main_channel() -> Result<(MainSender, MainReceiver), ChannelError> {
|
|||||||
Ok((MainSender { sender }, MainReceiver { receiver }))
|
Ok((MainSender { sender }, MainReceiver { receiver }))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct MainSender {
|
pub struct MainSender {
|
||||||
sender: Sender<Message>,
|
sender: Sender<Message>,
|
||||||
}
|
}
|
||||||
@ -97,7 +96,6 @@ impl MainSender {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct MainReceiver {
|
pub struct MainReceiver {
|
||||||
receiver: Receiver<Message>,
|
receiver: Receiver<Message>,
|
||||||
}
|
}
|
||||||
@ -209,7 +207,6 @@ pub fn intermediate_channel() -> Result<(IntermediateSender, IntermediateReceive
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct IntermediateSender {
|
pub struct IntermediateSender {
|
||||||
sender: Sender<Message>,
|
sender: Sender<Message>,
|
||||||
}
|
}
|
||||||
@ -229,7 +226,6 @@ impl IntermediateSender {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct IntermediateReceiver {
|
pub struct IntermediateReceiver {
|
||||||
receiver: Receiver<Message>,
|
receiver: Receiver<Message>,
|
||||||
}
|
}
|
||||||
@ -266,7 +262,6 @@ pub fn init_channel() -> Result<(InitSender, InitReceiver), ChannelError> {
|
|||||||
Ok((InitSender { sender }, InitReceiver { receiver }))
|
Ok((InitSender { sender }, InitReceiver { receiver }))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct InitSender {
|
pub struct InitSender {
|
||||||
sender: Sender<Message>,
|
sender: Sender<Message>,
|
||||||
}
|
}
|
||||||
@ -285,7 +280,6 @@ impl InitSender {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct InitReceiver {
|
pub struct InitReceiver {
|
||||||
receiver: Receiver<Message>,
|
receiver: Receiver<Message>,
|
||||||
}
|
}
|
||||||
|
@ -101,12 +101,7 @@ pub fn container_intermediate_process(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let cb: CloneCb = {
|
let cb: CloneCb = {
|
||||||
let args = args.clone();
|
Box::new(|| {
|
||||||
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 || {
|
|
||||||
if let Err(ret) = prctl::set_name("youki:[2:INIT]") {
|
if let Err(ret) = prctl::set_name("youki:[2:INIT]") {
|
||||||
tracing::error!(?ret, "failed to set name for child process");
|
tracing::error!(?ret, "failed to set name for child process");
|
||||||
return ret;
|
return ret;
|
||||||
@ -123,7 +118,7 @@ pub fn container_intermediate_process(
|
|||||||
tracing::error!(?err, "failed to close sender in the intermediate process");
|
tracing::error!(?err, "failed to close sender in the intermediate process");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
match container_init_process(&args, &mut main_sender, &mut init_receiver) {
|
match container_init_process(args, main_sender, init_receiver) {
|
||||||
Ok(_) => 0,
|
Ok(_) => 0,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
tracing::error!("failed to initialize container process: {e}");
|
tracing::error!("failed to initialize container process: {e}");
|
||||||
|
@ -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.
|
// cloned process, we have to be deligent about closing any unused channel.
|
||||||
// At minimum, we have to close down any unused senders. The corresponding
|
// At minimum, we have to close down any unused senders. The corresponding
|
||||||
// receivers will be cleaned up once the senders are closed down.
|
// receivers will be cleaned up once the senders are closed down.
|
||||||
let (main_sender, mut main_receiver) = channel::main_channel()?;
|
let (mut main_sender, mut main_receiver) = channel::main_channel()?;
|
||||||
let inter_chan = channel::intermediate_channel()?;
|
let mut inter_chan = channel::intermediate_channel()?;
|
||||||
let init_chan = channel::init_channel()?;
|
let mut init_chan = channel::init_channel()?;
|
||||||
|
|
||||||
let cb: CloneCb = {
|
let cb: CloneCb = {
|
||||||
let container_args = container_args.clone();
|
Box::new(|| {
|
||||||
let mut main_sender = main_sender.clone();
|
|
||||||
let mut inter_chan = inter_chan.clone();
|
|
||||||
let mut init_chan = init_chan.clone();
|
|
||||||
Box::new(move || {
|
|
||||||
if let Err(ret) = prctl::set_name("youki:[1:INTER]") {
|
if let Err(ret) = prctl::set_name("youki:[1:INTER]") {
|
||||||
tracing::error!(?ret, "failed to set name for child process");
|
tracing::error!(?ret, "failed to set name for child process");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
match container_intermediate_process::container_intermediate_process(
|
match container_intermediate_process::container_intermediate_process(
|
||||||
&container_args,
|
container_args,
|
||||||
&mut inter_chan,
|
&mut inter_chan,
|
||||||
&mut init_chan,
|
&mut init_chan,
|
||||||
&mut main_sender,
|
&mut main_sender,
|
||||||
|
@ -32,7 +32,7 @@ pub enum CloneError {
|
|||||||
/// pass in a child stack, which is empty. By storing the closure in heap, we
|
/// 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
|
/// can then in the new process to re-box the heap memory back to a closure
|
||||||
/// correctly.
|
/// correctly.
|
||||||
pub type CloneCb = Box<dyn FnMut() -> i32>;
|
pub type CloneCb<'a> = Box<dyn FnMut() -> i32 + 'a>;
|
||||||
|
|
||||||
// Clone a sibling process that shares the same parent as the calling
|
// 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
|
// process. This is used to launch the container init process so the parent
|
||||||
|
Loading…
Reference in New Issue
Block a user