Skip to content

Commit

Permalink
Merge pull request #41 from utam0k/revert-async-mounts
Browse files Browse the repository at this point in the history
revert asynchronous devices mounting.
  • Loading branch information
utam0k authored May 28, 2021
2 parents ea9186d + bed4396 commit 37243cd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
14 changes: 6 additions & 8 deletions src/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,21 +157,19 @@ fn init_process(
namespaces: Namespaces,
) -> Result<()> {
let proc = spec.process.clone();
let clone_spec = std::sync::Arc::new(spec);
let clone_rootfs = std::sync::Arc::new(rootfs.clone());

command.set_hostname(&clone_spec.hostname.as_str())?;
if clone_spec.process.no_new_privileges {
command.set_hostname(&spec.hostname.as_str())?;
if spec.process.no_new_privileges {
let _ = prctl::set_no_new_privileges(true);
}

futures::executor::block_on(rootfs::prepare_rootfs(
clone_spec,
clone_rootfs,
rootfs::prepare_rootfs(
&spec,
&rootfs,
namespaces
.clone_flags
.contains(sched::CloneFlags::CLONE_NEWUSER),
))?;
)?;

command.pivot_rootfs(&rootfs)?;

Expand Down
23 changes: 9 additions & 14 deletions src/rootfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::fs::OpenOptions;
use std::fs::{canonicalize, create_dir_all, remove_file};
use std::os::unix::fs::symlink;
use std::path::{Path, PathBuf};
use std::sync::Arc;

use anyhow::{bail, Result};
use nix::errno::Errno;
Expand All @@ -17,11 +16,7 @@ use nix::unistd::{Gid, Uid};
use oci_spec::{LinuxDevice, LinuxDeviceType, Mount, Spec};
use crate::utils::PathBufExt;

pub async fn prepare_rootfs(
spec: Arc<Spec>,
rootfs: Arc<PathBuf>,
bind_devices: bool,
) -> Result<()> {
pub fn prepare_rootfs(spec: &Spec, rootfs: &Path, bind_devices: bool) -> Result<()> {
let mut flags = MsFlags::MS_REC;
match spec.linux {
Some(ref linux) => match linux.rootfs_propagation.as_ref() {
Expand All @@ -35,9 +30,9 @@ pub async fn prepare_rootfs(
nix_mount(None::<&str>, "/", None::<&str>, flags, None::<&str>)?;

log::debug!("mount root fs {:?}", rootfs);
nix_mount(
Some(rootfs.as_ref()),
rootfs.as_ref(),
nix_mount::<Path, Path, str, str>(
Some(&rootfs),
&rootfs,
None::<&str>,
MsFlags::MS_BIND | MsFlags::MS_REC,
None::<&str>,
Expand All @@ -50,18 +45,18 @@ pub async fn prepare_rootfs(
// skip
log::warn!("A feature of cgoup is unimplemented.");
} else if m.destination == PathBuf::from("/dev") {
mount_to_container(&m, rootfs.as_ref(), flags & !MsFlags::MS_RDONLY, &data, &ml)?;
mount_to_container(&m, rootfs, flags & !MsFlags::MS_RDONLY, &data, &ml)?;
} else {
mount_to_container(&m, rootfs.as_ref(), flags, &data, &ml)?;
mount_to_container(&m, rootfs, flags, &data, &ml)?;
}
}

let olddir = getcwd()?;
chdir(rootfs.as_ref())?;
chdir(rootfs)?;

setup_default_symlinks(&rootfs.as_ref())?;
setup_default_symlinks(rootfs)?;
create_devices(&spec.linux.as_ref().unwrap().devices, bind_devices)?;
setup_ptmx(rootfs.as_ref())?;
setup_ptmx(rootfs)?;

chdir(&olddir)?;

Expand Down

0 comments on commit 37243cd

Please sign in to comment.