Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] 279 increate the code coverage of src rootfs #340

21 changes: 12 additions & 9 deletions src/process/init.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::args::ContainerArgs;
use crate::apparmor;
use crate::{
capabilities, hooks, namespaces::Namespaces, process::channel, rootfs, rootless::Rootless,
seccomp, tty, utils,
capabilities, hooks, namespaces::Namespaces, process::channel, rootfs::RootFS,
rootless::Rootless, seccomp, tty, utils,
};
use anyhow::{bail, Context, Result};
use nix::mount::mount as nix_mount;
Expand Down Expand Up @@ -167,7 +167,7 @@ pub fn container_init(
let linux = spec.linux().as_ref().context("no linux in spec")?;
let proc = spec.process().as_ref().context("no process in spec")?;
let mut envs: Vec<String> = proc.env().as_ref().unwrap_or(&vec![]).clone();
let rootfs = &args.rootfs;
let rootfs_path = &args.rootfs;
let hooks = spec.hooks().as_ref();
let container = args.container.as_ref();
let namespaces = Namespaces::from(linux.namespaces().as_ref());
Expand Down Expand Up @@ -215,8 +215,10 @@ pub fn container_init(
.context("Failed to run create container hooks")?;
}

let rootfs = RootFS::new();
let bind_service = namespaces.get(LinuxNamespaceType::User).is_some();
rootfs::prepare_rootfs(spec, rootfs, bind_service)
rootfs
.prepare_rootfs(spec, rootfs_path, bind_service)
.with_context(|| "Failed to prepare rootfs")?;

// Entering into the rootfs jail. If mount namespace is specified, then
Expand All @@ -226,15 +228,16 @@ pub fn container_init(
if namespaces.get(LinuxNamespaceType::Mount).is_some() {
// change the root of filesystem of the process to the rootfs
command
.pivot_rootfs(rootfs)
.with_context(|| format!("Failed to pivot root to {:?}", rootfs))?;
.pivot_rootfs(rootfs_path)
.with_context(|| format!("Failed to pivot root to {:?}", rootfs_path))?;
} else {
command
.chroot(rootfs)
.with_context(|| format!("Failed to chroot to {:?}", rootfs))?;
.chroot(rootfs_path)
.with_context(|| format!("Failed to chroot to {:?}", rootfs_path))?;
}

rootfs::adjust_root_mount_propagation(linux)
rootfs
.adjust_root_mount_propagation(linux)
.context("Failed to set propagation type of root mount")?;

if let Some(kernel_params) = linux.sysctl() {
Expand Down
Loading