[−][src]Crate sysctl
A simplified interface to the sysctl system call.
Currently built for and only tested on FreeBSD.
Example: Get description and value
extern crate sysctl; #[cfg(not(target_os = "macos"))] fn main() { let ctl = sysctl::Ctl::new("kern.osrevision") .expect("could not get sysctl"); let d = ctl.description() .expect("could not get description"); println!("Description: {:?}", d); let val_enum = ctl.value() .expect("could not get value"); if let sysctl::CtlValue::Int(val) = val_enum { println!("Value: {}", val); } } #[cfg(target_os = "macos")] fn main() { let mut ctl = sysctl::Ctl::new("kern.osrevision") .expect("could not get sysctl"); // description is not available on macos let val_enum = ctl.value() .expect("could not get value"); if let sysctl::CtlValue::Int(val) = val_enum { println!("Value: {}", val); } }
Example: Get value as struct
extern crate sysctl; extern crate libc; use libc::c_int; #[derive(Debug)] #[repr(C)] struct ClockInfo { hz: c_int, /* clock frequency */ tick: c_int, /* micro-seconds per hz tick */ spare: c_int, stathz: c_int, /* statistics clock frequency */ profhz: c_int, /* profiling clock frequency */ } fn main() { println!("{:?}", sysctl::value_as::<ClockInfo>("kern.clockrate")); }
Structs
| Ctl |
This struct represents a system control. |
| CtlFlags | |
| CtlInfo |
A structure representing control metadata |
| CtlIter |
An iterator over Sysctl entries. |
Enums
| CtlType |
An Enum that represents a sysctl's type information. |
| CtlValue |
An Enum that holds all values returned by sysctl calls.
Extract inner value with |
| SysctlError |
Constants
Functions
| next_oid |
Get the next OID. |
| set_oid_value | |
| set_value |
Sets the value of a sysctl. Fetches and returns the new value if successful, or a SysctlError on failure |
| value |
Takes the name of the OID as argument and returns a result containing the sysctl value if success, or a SysctlError on failure |
| value_as |
A generic function that takes a string as argument and returns a result containing the sysctl value if success, or a SysctlError on failure. |
| value_oid |
Takes an OID as argument and returns a result containing the sysctl value if success, or a SysctlError on failure |
| value_oid_as |
A generic function that takes an OID as argument and returns a result containing the sysctl value if success, or a SysctlError on failure |