Struct greenhook::Supervisor

source ·
pub struct Supervisor { /* private fields */ }
Expand description

The main component of greenhook.

Implementations§

source§

impl Supervisor

source

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();
source

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);
source

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();
source

pub fn wait( child: &mut Child, thread_handle: JoinHandle<()>, pool_handle: ThreadPool ) -> Result<ExitStatus, Error>

Wait for the child process to exit and cleanup the supervisor thread and thread pool. It returns WaitStatus of the child process.

Examples
let status = Supervisor::wait(&mut child, thread_handle, pool).unwrap();

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.