pub struct Sandbox { /* private fields */ }Expand description
Build sandbox manager.
Implementations§
Source§impl Sandbox
impl Sandbox
pub fn mount_bindfs( &self, src: &Path, dest: &Path, opts: &[&str], ) -> Result<Option<ExitStatus>>
pub fn mount_devfs( &self, _src: &Path, dest: &Path, opts: &[&str], ) -> Result<Option<ExitStatus>>
pub fn mount_fdfs( &self, _src: &Path, dest: &Path, opts: &[&str], ) -> Result<Option<ExitStatus>>
pub fn mount_nfs( &self, src: &Path, dest: &Path, opts: &[&str], ) -> Result<Option<ExitStatus>>
pub fn mount_procfs( &self, _src: &Path, dest: &Path, opts: &[&str], ) -> Result<Option<ExitStatus>>
pub fn mount_tmpfs( &self, _src: &Path, dest: &Path, opts: &[&str], ) -> Result<Option<ExitStatus>>
pub fn unmount_bindfs(&self, dest: &Path) -> Result<Option<ExitStatus>>
pub fn unmount_devfs(&self, dest: &Path) -> Result<Option<ExitStatus>>
pub fn unmount_fdfs(&self, dest: &Path) -> Result<Option<ExitStatus>>
pub fn unmount_nfs(&self, dest: &Path) -> Result<Option<ExitStatus>>
pub fn unmount_procfs(&self, dest: &Path) -> Result<Option<ExitStatus>>
pub fn unmount_tmpfs(&self, dest: &Path) -> Result<Option<ExitStatus>>
Sourcepub fn kill_processes(&self, sandbox: &Path)
pub fn kill_processes(&self, sandbox: &Path)
Kill all processes with open file handles within a sandbox path.
Uses procfs to scan all processes for file descriptors, cwd, or root
that point into the sandbox directory. This is more thorough than
fuser which only checks the exact path, not files within subdirs.
Source§impl Sandbox
impl Sandbox
Sourcepub fn enabled(&self) -> bool
pub fn enabled(&self) -> bool
Return whether sandboxes have been enabled.
This is based on whether a valid sandboxes section has been
specified in the config file.
Sourcepub fn command(&self, id: usize, cmd: &Path) -> Command
pub fn command(&self, id: usize, cmd: &Path) -> Command
Create a Command that runs in the sandbox (via chroot) if enabled, or directly if sandboxes are disabled.
Sourcepub fn kill_processes_by_id(&self, id: usize)
pub fn kill_processes_by_id(&self, id: usize)
Kill all processes in a sandbox by id. This is used for graceful shutdown on Ctrl+C.
Sourcepub fn create(&self, id: usize) -> Result<()>
pub fn create(&self, id: usize) -> Result<()>
Create a single sandbox by id. If the sandbox already exists and is valid (has lock), this is a no-op.
Sourcepub fn execute(
&self,
id: usize,
script: &Path,
envs: Vec<(String, String)>,
stdin_data: Option<&str>,
protected: bool,
) -> Result<Child>
pub fn execute( &self, id: usize, script: &Path, envs: Vec<(String, String)>, stdin_data: Option<&str>, protected: bool, ) -> Result<Child>
Execute a script file with supplied environment variables and optional stdin data.
If protected is true, the process is placed in its own process group to isolate it from terminal signals (Ctrl+C). Use this for cleanup scripts that must complete even during shutdown.
Sourcepub fn execute_script(
&self,
id: usize,
content: &str,
envs: Vec<(String, String)>,
) -> Result<Child>
pub fn execute_script( &self, id: usize, content: &str, envs: Vec<(String, String)>, ) -> Result<Child>
Execute inline script content via /bin/sh.
Sourcepub fn execute_command<I, S>(
&self,
id: usize,
cmd: &Path,
args: I,
envs: Vec<(String, String)>,
) -> Result<Child>
pub fn execute_command<I, S>( &self, id: usize, cmd: &Path, args: I, envs: Vec<(String, String)>, ) -> Result<Child>
Execute a command directly without shell interpretation.
Sourcepub fn run_pre_build(
&self,
id: usize,
config: &Config,
envs: Vec<(String, String)>,
) -> Result<bool>
pub fn run_pre_build( &self, id: usize, config: &Config, envs: Vec<(String, String)>, ) -> Result<bool>
Run the pre-build script if configured. Returns Ok(true) if script ran successfully or wasn’t configured, Ok(false) if script failed.
Sourcepub fn run_post_build(
&self,
id: usize,
config: &Config,
envs: Vec<(String, String)>,
) -> Result<bool>
pub fn run_post_build( &self, id: usize, config: &Config, envs: Vec<(String, String)>, ) -> Result<bool>
Run the post-build script if configured. Returns Ok(true) if script ran successfully or wasn’t configured, Ok(false) if script failed.
Post-build scripts run with signal protection (process_group(0)) to ensure cleanup completes even during shutdown from Ctrl+C.
Sourcepub fn create_all(&self, count: usize) -> Result<()>
pub fn create_all(&self, count: usize) -> Result<()>
Create all sandboxes in parallel, rolling back on failure.
Sourcepub fn destroy_all(&self, count: usize) -> Result<()>
pub fn destroy_all(&self, count: usize) -> Result<()>
Destroy all sandboxes in parallel. Continue on errors to ensure all sandboxes are attempted, printing each error as it occurs.
Sourcepub fn count_existing(&self, count: usize) -> usize
pub fn count_existing(&self, count: usize) -> usize
Count existing sandboxes (complete or incomplete).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Sandbox
impl !RefUnwindSafe for Sandbox
impl Send for Sandbox
impl Sync for Sandbox
impl Unpin for Sandbox
impl !UnwindSafe for Sandbox
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more