mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-29 16:57:18 +00:00
agent/rustjail: implement functions to chroot
Use conditional compilation (#[cfg]) to change chroot behaviour at compilation time. For example, such function will just return `Ok(())` when the unit tests are being compiled, otherwise real chroot operation is performed. Signed-off-by: Julio Montes <julio.montes@intel.com>
This commit is contained in:
parent
fe0f219819
commit
a36f93c947
@ -483,6 +483,14 @@ fn parse_mount_table() -> Result<Vec<Info>> {
|
|||||||
Ok(infos)
|
Ok(infos)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
fn chroot<P: ?Sized + NixPath>(path: &P) -> Result<(), nix::Error> {
|
||||||
|
#[cfg(not(test))]
|
||||||
|
return unistd::chroot(path);
|
||||||
|
#[cfg(test)]
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
pub fn ms_move_root(rootfs: &str) -> Result<bool> {
|
pub fn ms_move_root(rootfs: &str) -> Result<bool> {
|
||||||
unistd::chdir(rootfs)?;
|
unistd::chdir(rootfs)?;
|
||||||
let mount_infos = parse_mount_table()?;
|
let mount_infos = parse_mount_table()?;
|
||||||
@ -544,7 +552,7 @@ pub fn ms_move_root(rootfs: &str) -> Result<bool> {
|
|||||||
MsFlags::MS_MOVE,
|
MsFlags::MS_MOVE,
|
||||||
None::<&str>,
|
None::<&str>,
|
||||||
)?;
|
)?;
|
||||||
unistd::chroot(".")?;
|
chroot(".")?;
|
||||||
unistd::chdir("/")?;
|
unistd::chdir("/")?;
|
||||||
|
|
||||||
Ok(true)
|
Ok(true)
|
||||||
|
Loading…
Reference in New Issue
Block a user