Struct greenhook::Supervisor
source · pub struct Supervisor { /* private fields */ }
Expand description
The main component of greenhook.
Implementations§
source§impl Supervisor
impl Supervisor
sourcepub fn new(thread_num: usize) -> Result<Self, Error>
pub fn new(thread_num: usize) -> Result<Self, Error>
Create a new Supervisor
object. You can specify the number of threads in the thread pool.
This function will also check your kernel version and show warning or return error if necessary.
Examples
use greenhook::Supervisor;
let supervisor = Supervisor::new(4).unwrap();
sourcepub fn insert_handler(
&mut self,
syscall: ScmpSyscall,
handler: impl Fn(&UNotifyEventRequest) -> ScmpNotifResp + Send + Sync + 'static
)
pub fn insert_handler( &mut self, syscall: ScmpSyscall, handler: impl Fn(&UNotifyEventRequest) -> ScmpNotifResp + Send + Sync + 'static )
Insert a user-defined handler function for a syscall.
Examples
use greenhook::{Supervisor, UNotifyEventRequest};
use libseccomp::ScmpSyscall;
fn close_handler(req: &UNotifyEventRequest) -> libseccomp::ScmpNotifResp {
println!("close");
unsafe { req.continue_syscall() }
}
let mut supervisor = Supervisor::new(4).unwrap();
supervisor.insert_handler(ScmpSyscall::new("open"), |req| {
println!("open: {}", req.get_request().data.args[0]);
unsafe { req.continue_syscall() }
});
supervisor.insert_handler(ScmpSyscall::new("close"), close_handler);
sourcepub fn exec(
self,
cmd: &mut Command
) -> Result<(Child, JoinHandle<()>, ThreadPool), Error>
pub fn exec( self, cmd: &mut Command ) -> Result<(Child, JoinHandle<()>, ThreadPool), Error>
Run a command with seccomp filter.
This method will fork a child process, do some preparations and run the command in it.
It returns a Child, a JoinHandle of supervising thread, and a ThreadPool handle of syscall user functions.
It’s recommended to use Supervisor::wait()
to wait for the child process.
Examples
ⓘ
let (mut child, handle, pool) = supervisor.exec(&mut cmd).unwrap();
sourcepub fn wait(
child: &mut Child,
thread_handle: JoinHandle<()>,
pool_handle: ThreadPool
) -> Result<ExitStatus, Error>
pub fn wait( child: &mut Child, thread_handle: JoinHandle<()>, pool_handle: ThreadPool ) -> Result<ExitStatus, Error>
Auto Trait Implementations§
impl !RefUnwindSafe for Supervisor
impl Send for Supervisor
impl Sync for Supervisor
impl Unpin for Supervisor
impl !UnwindSafe for Supervisor
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
Mutably borrows from an owned value. Read more