Skip to content

Commit

Permalink
adding mount syscall in syscall trait for better mock testing
Browse files Browse the repository at this point in the history
  • Loading branch information
tommady committed Sep 30, 2021
1 parent 6a04ddc commit 7d9f4ba
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/syscall/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,25 @@ impl Syscall for LinuxSyscall {

Ok(())
}

fn mount(
&self,
source: Option<&str>,
target: &str,
fstype: Option<&str>,
flags: MsFlags,
data: Option<&str>,
) -> Result<()> {
if let Err(e) = nix::mount::mount(source, target, fstype, flags, data) {
bail!(
"Failed to mount source:{:?}, target:{:?}, fstype:{:?}, flags:{:?}, data:{:?}",
source,
target,
fstype,
flags,
data
);
}
Ok(())
}
}
9 changes: 9 additions & 0 deletions src/syscall/syscall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{any::Any, ffi::OsStr, path::Path, sync::Arc};
use anyhow::Result;
use caps::{errors::CapsError, CapSet, CapsHashSet};
use nix::{
mount::MsFlags,
sched::CloneFlags,
unistd::{Gid, Uid},
};
Expand All @@ -27,6 +28,14 @@ pub trait Syscall {
fn set_hostname(&self, hostname: &str) -> Result<()>;
fn set_rlimit(&self, rlimit: &LinuxRlimit) -> Result<()>;
fn get_pwuid(&self, uid: u32) -> Option<Arc<OsStr>>;
fn mount(
&self,
source: Option<&str>,
target: &str,
fstype: Option<&str>,
flags: MsFlags,
data: Option<&str>,
) -> Result<()>;
}

pub fn create_syscall() -> Box<dyn Syscall> {
Expand Down
11 changes: 11 additions & 0 deletions src/syscall/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ impl Syscall for TestHelperSyscall {
fn chroot(&self, _: &std::path::Path) -> anyhow::Result<()> {
todo!()
}

fn mount(
&self,
_source: Option<&str>,
_target: &str,
_fstype: Option<&str>,
_flags: nix::mount::MsFlags,
_data: Option<&str>,
) -> anyhow::Result<()> {
todo!()
}
}

impl TestHelperSyscall {
Expand Down

0 comments on commit 7d9f4ba

Please sign in to comment.