mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-25 15:02:45 +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
25c91afbea
commit
d79fad2dd8
@ -483,6 +483,14 @@ fn parse_mount_table() -> Result<Vec<Info>> {
|
||||
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> {
|
||||
unistd::chdir(rootfs)?;
|
||||
let mount_infos = parse_mount_table()?;
|
||||
@ -544,7 +552,7 @@ pub fn ms_move_root(rootfs: &str) -> Result<bool> {
|
||||
MsFlags::MS_MOVE,
|
||||
None::<&str>,
|
||||
)?;
|
||||
unistd::chroot(".")?;
|
||||
chroot(".")?;
|
||||
unistd::chdir("/")?;
|
||||
|
||||
Ok(true)
|
||||
|
Loading…
Reference in New Issue
Block a user