Skip to content

Commit

Permalink
Merge pull request #90 from YJDoc2/main
Browse files Browse the repository at this point in the history
Rename Cond to Pipe
  • Loading branch information
utam0k authored Jun 15, 2021
2 parents 17a036d + 2d32459 commit 2f14718
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ extern crate quickcheck;
pub mod capabilities;
pub mod cgroups;
pub mod command;
pub mod cond;
pub mod container;
pub mod create;
pub mod logger;
pub mod namespaces;
pub mod notify_socket;
pub mod pipe;
pub mod process;
pub mod rootfs;
pub mod signal;
Expand Down
12 changes: 6 additions & 6 deletions src/cond.rs → src/pipe.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
//! Conditional variable that performs busy waiting on lock
//! Unix pipe wrapper
use std::os::unix::io::RawFd;

use anyhow::Result;
use nix::fcntl::OFlag;
use nix::unistd::{close, pipe2, read};

pub struct Cond {
pub struct Pipe {
rfd: RawFd,
wfd: RawFd,
}

impl Cond {
pub fn new() -> Result<Cond> {
impl Pipe {
pub fn new() -> Result<Self> {
// Sets as close-on-execution
let (rfd, wfd) = pipe2(OFlag::O_CLOEXEC)?;
Ok(Cond { rfd, wfd })
let (rfd, wfd) = pipe2(OFlag::O_CLOEXEC)?;
Ok(Pipe { rfd, wfd })
}

pub fn wait(&self) -> Result<()> {
Expand Down
8 changes: 4 additions & 4 deletions src/process/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use nix::unistd::Pid;
use crate::cgroups::common::CgroupManager;
use crate::container::ContainerStatus;
use crate::process::{child, init, parent, Process};
use crate::{cond::Cond, container::Container};
use crate::{container::Container, pipe::Pipe};

/// Function to perform the first fork for in order to run the container process
pub fn fork_first<P: AsRef<Path>>(
Expand All @@ -27,7 +27,7 @@ pub fn fork_first<P: AsRef<Path>>(
cmanager: Box<dyn CgroupManager>,
) -> Result<Process> {
// create a new pipe
let ccond = Cond::new()?;
let cpipe = Pipe::new()?;

// create new parent process structure
let (mut parent, sender_for_parent) = parent::ParentProcess::new()?;
Expand Down Expand Up @@ -55,12 +55,12 @@ pub fn fork_first<P: AsRef<Path>>(
sched::unshare(sched::CloneFlags::CLONE_NEWUSER)?;
}

ccond.notify()?;
cpipe.notify()?;
Ok(Process::Child(child))
}
// in the parent process
unistd::ForkResult::Parent { child } => {
ccond.wait()?;
cpipe.wait()?;

// wait for child to fork init process and report back its pid
let init_pid = parent.wait_for_child_ready()?;
Expand Down

0 comments on commit 2f14718

Please sign in to comment.