Debian Codegraph @

examples/all_caps.rs

raw symbols SCIP
1 /*!
2 A simple example showing how to introspect all available capabilities.
3
4 This differentiates between:
5 * library set: the static set hardcoded in the library at build-time.
6 * runtime set: the dynamic set available in the running kernel.
7
8 The runtime set can be introspected in two different ways: via procfs
9 (faster but not always possible) or via probing (slower). Where both
10 mechanisms are available, they produce the exact same result.
11 !*/
12
13 type ExResult<T> = Result<T, Box<dyn std::error::Error + 'static>>;
14
15 fn main() -> ExResult<()> {
16 let library_set = caps::all();
17 let runtime_set = caps::runtime::procfs_all_supported(None).unwrap_or_else(|e| {
18 eprintln!("procfs introspection failed: {}", e);
19 caps::runtime::thread_all_supported()
20 });
21
22 println!("Capabilities tally:");
23 println!(" -> known by this library: {}.", library_set.len());
24 println!(" -> known by the current kernel: {}.\n", runtime_set.len());
25
26 println!("Library vs kernel differences:");
27 println!(
28 " -> newer caps only in the library set: {:?}.",
29 library_set.difference(&runtime_set)
30 );
31 println!(
32 " -> newer caps only in the current kernel set: {:?}.",
33 runtime_set.difference(&library_set)
34 );
35
36 Ok(())
37 }