Struct ModUnloader

Source
pub struct ModUnloader { /* private fields */ }
Expand description

Module unloader.

Asynchronous methods can be enabled via the optional async feature.

Implementations§

Source§

impl ModUnloader

Source

pub fn new() -> Self

Create a new default ModLoader.

Examples found in repository?
examples/async-unload.rs (line 23)
16fn main() {
17    // Get from cmdline the name of the module to unload.
18    let modname = std::env::args().nth(1).expect("missing module name");
19
20    // Assemble a future to unload the module; if busy,
21    // retry every 500ms and time out after 5 seconds.
22    let pause_ms = num::NonZeroU64::new(500).unwrap();
23    let modunload = likemod::ModUnloader::new().unload_async(&modname, pause_ms);
24    let tout = time::Duration::from_secs(15);
25    let fut = timeout::Timeout::new(modunload, tout);
26
27    // Run the future until completion.
28    if let Err(err) = current_thread::block_on_all(fut) {
29        eprintln!("FAILED: {:?}", err);
30        process::exit(1)
31    }
32
33    // Success!
34    println!("module '{}' unloaded.", modname);
35}
Source

pub fn forced(self, force_unload: bool) -> Self

Set whether a forced unload should be performed.

A force unload will taint the kernel and can leave the host in an unstable state, or cause data loss.

Source

pub fn unload_sync<S: AsRef<str>>( &self, modname: S, blocking: bool, ) -> Result<()>

Unload module by name, synchronously.

If blocking is enabled, this can block at syscall level (putting the process in D state) while waiting for module reference count to be 0 for clean unloading (unless forced).

It is usually recommended not to set blocking, as the process cannot be killed while blocked on syscall. Consider using unload_async instead.

Source

pub fn unload_async<S: AsRef<str>>( &self, modname: S, pause_millis: NonZeroU64, ) -> Box<dyn Future<Item = (), Error = Error>>

Unload module by name, asynchronously.

If the module is currently in use, this will continuously retry unloading at fixed intervals after pausing for the specified amount of milliseconds. This requires enabling the async optional feature.

Examples found in repository?
examples/async-unload.rs (line 23)
16fn main() {
17    // Get from cmdline the name of the module to unload.
18    let modname = std::env::args().nth(1).expect("missing module name");
19
20    // Assemble a future to unload the module; if busy,
21    // retry every 500ms and time out after 5 seconds.
22    let pause_ms = num::NonZeroU64::new(500).unwrap();
23    let modunload = likemod::ModUnloader::new().unload_async(&modname, pause_ms);
24    let tout = time::Duration::from_secs(15);
25    let fut = timeout::Timeout::new(modunload, tout);
26
27    // Run the future until completion.
28    if let Err(err) = current_thread::block_on_all(fut) {
29        eprintln!("FAILED: {:?}", err);
30        process::exit(1)
31    }
32
33    // Success!
34    println!("module '{}' unloaded.", modname);
35}

Trait Implementations§

Source§

impl Clone for ModUnloader

Source§

fn clone(&self) -> ModUnloader

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ModUnloader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ModUnloader

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.