diff --git a/FEATURES.md b/FEATURES.md index b7759fa..9f5af51 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -1,6 +1,8 @@ Supported Features * ✅ `/proc/buddyinfo` +* ✅ `/proc/cmdline` + * ✅ `/proc/cpuinfo` * ✅ `/proc/loadavg` diff --git a/examples/cmdline.rs b/examples/cmdline.rs new file mode 100644 index 0000000..d9310e4 --- /dev/null +++ b/examples/cmdline.rs @@ -0,0 +1,6 @@ +use procsys::cmdline; + +fn main() { + let sys_cmdline = cmdline::collect().expect("system boot cmdline"); + println!("{:?}", sys_cmdline); +} diff --git a/src/cmdline.rs b/src/cmdline.rs new file mode 100644 index 0000000..6da5004 --- /dev/null +++ b/src/cmdline.rs @@ -0,0 +1,38 @@ +use std::path::Path; + +use crate::{error::CollectResult, utils}; + +/// collects information about system boot cmdline +/// # Example +/// ``` +/// use procsys::cmdline; +/// +/// let sys_cmdline = cmdline::collect().expect("system boot cmdline"); +/// println!("{:?}", sys_cmdline); +/// +pub fn collect() -> CollectResult> { + let mut boot_cmdline: Vec = Vec::new(); + + let bootcmd = utils::collect_info_string("cmdline", Path::new("/proc"))?; + + if bootcmd.is_some() { + boot_cmdline = bootcmd + .unwrap() + .split_whitespace() + .map(str::to_string) + .collect(); + } + + Ok(boot_cmdline) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn sys_bootcmd() { + let bootcmd = collect().expect("system boot cmdline"); + assert!(!bootcmd.is_empty()) + } +} diff --git a/src/lib.rs b/src/lib.rs index 47644f2..c3a61ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,7 @@ #![doc = include_str!("../README.md")] pub mod buddyinfo; +pub mod cmdline; pub mod cpuinfo; pub mod error; pub mod kernel_random;