mirror of
https://github.com/orhun/systeroid
synced 2024-10-01 13:13:32 +00:00
feat(kernel): fetch the available kernel parameters
This commit is contained in:
parent
71d3da2cf8
commit
146ec1bba9
71
Cargo.lock
generated
71
Cargo.lock
generated
|
@ -17,6 +17,12 @@ version = "1.0.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "block-buffer"
|
||||
version = "0.7.3"
|
||||
|
@ -329,6 +335,15 @@ version = "0.6.25"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
|
||||
|
||||
[[package]]
|
||||
name = "same-file"
|
||||
version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
|
||||
dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "scopeguard"
|
||||
version = "1.1.0"
|
||||
|
@ -358,6 +373,19 @@ dependencies = [
|
|||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sysctl"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "963488c73b34185a9028742c2be0219ed1d8558e59f85c3b466a4f54affba936"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"byteorder",
|
||||
"libc",
|
||||
"thiserror",
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "systeroid"
|
||||
version = "0.1.0"
|
||||
|
@ -372,6 +400,7 @@ dependencies = [
|
|||
name = "systeroid-core"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"sysctl",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
|
@ -428,3 +457,45 @@ name = "unicode-xid"
|
|||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
|
||||
|
||||
[[package]]
|
||||
name = "walkdir"
|
||||
version = "2.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56"
|
||||
dependencies = [
|
||||
"same-file",
|
||||
"winapi",
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||
dependencies = [
|
||||
"winapi-i686-pc-windows-gnu",
|
||||
"winapi-x86_64-pc-windows-gnu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-util"
|
||||
version = "0.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
|
|
@ -6,3 +6,4 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
thiserror = "1.0.29"
|
||||
sysctl = "0.4.2"
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
/// Linux kernel documentation.
|
||||
pub mod docs;
|
||||
|
||||
/// Linux kernel parameter handler.
|
||||
pub mod sysctl;
|
||||
|
||||
/// File reader.
|
||||
pub mod reader;
|
||||
|
||||
|
|
35
systeroid-core/src/sysctl.rs
Normal file
35
systeroid-core/src/sysctl.rs
Normal file
|
@ -0,0 +1,35 @@
|
|||
use sysctl::{CtlIter, Sysctl as SysctlImpl};
|
||||
|
||||
/// Representation of a kernel parameter.
|
||||
pub struct Parameter {
|
||||
/// Name of the kernel parameter.
|
||||
pub name: String,
|
||||
/// Value of the kernel parameter.
|
||||
pub value: String,
|
||||
/// Description of the kernel parameter
|
||||
pub description: Option<String>,
|
||||
}
|
||||
|
||||
/// Sysctl wrapper for managing the kernel parameters.
|
||||
pub struct Sysctl {
|
||||
/// Available kernel parameters.
|
||||
pub parameters: Vec<Parameter>,
|
||||
}
|
||||
|
||||
impl Sysctl {
|
||||
/// Constructs a new instance by fetching the available kernel parameters.
|
||||
pub fn init() -> Self {
|
||||
Self {
|
||||
parameters: CtlIter::root()
|
||||
.filter_map(Result::ok)
|
||||
.filter_map(|ctl| {
|
||||
Some(Parameter {
|
||||
name: ctl.name().ok()?,
|
||||
value: ctl.value_string().ok()?,
|
||||
description: ctl.description().ok(),
|
||||
})
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,10 +12,13 @@ use std::sync::Mutex;
|
|||
use systeroid_core::docs::SysctlSection;
|
||||
use systeroid_core::error::{Error, Result};
|
||||
use systeroid_core::reader;
|
||||
use systeroid_core::sysctl::Sysctl;
|
||||
use systeroid_parser::parser::RstParser;
|
||||
|
||||
/// Runs `systeroid`.
|
||||
pub fn run(args: Args) -> Result<()> {
|
||||
let sysctl = Sysctl::init();
|
||||
|
||||
if let Some(kernel_docs) = args.kernel_docs {
|
||||
let sysctl_docs = kernel_docs.join("admin-guide").join("sysctl");
|
||||
if !sysctl_docs.exists() {
|
||||
|
@ -49,5 +52,9 @@ pub fn run(args: Args) -> Result<()> {
|
|||
}
|
||||
}
|
||||
|
||||
for param in sysctl.parameters {
|
||||
println!("{}: {} ({:?})", param.name, param.value, param.description);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue