pub struct ModUnloader { /* private fields */ }
Expand description
Module unloader.
Asynchronous methods can be enabled via the optional async
feature.
Implementations§
Source§impl ModUnloader
impl ModUnloader
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new default ModLoader
.
Examples found in repository?
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}
Sourcepub fn forced(self, force_unload: bool) -> Self
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.
Sourcepub fn unload_sync<S: AsRef<str>>(
&self,
modname: S,
blocking: bool,
) -> Result<()>
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.
Sourcepub fn unload_async<S: AsRef<str>>(
&self,
modname: S,
pause_millis: NonZeroU64,
) -> Box<dyn Future<Item = (), Error = Error>>
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?
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
impl Clone for ModUnloader
Source§fn clone(&self) -> ModUnloader
fn clone(&self) -> ModUnloader
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more