Skip to content

Commit

Permalink
Merge pull request #14 from navidys/develop
Browse files Browse the repository at this point in the history
added /proc/cmdline
  • Loading branch information
navidys authored Aug 3, 2024
2 parents b951477 + 10aba6a commit 5d64620
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions FEATURES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Supported Features
*`/proc/buddyinfo`

*`/proc/cmdline`

*`/proc/cpuinfo`

*`/proc/loadavg`
Expand Down
6 changes: 6 additions & 0 deletions examples/cmdline.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use procsys::cmdline;

fn main() {
let sys_cmdline = cmdline::collect().expect("system boot cmdline");
println!("{:?}", sys_cmdline);
}
38 changes: 38 additions & 0 deletions src/cmdline.rs
Original file line number Diff line number Diff line change
@@ -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<Vec<String>> {
let mut boot_cmdline: Vec<String> = 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())
}
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 5d64620

Please sign in to comment.