Expand description
A simplified interface to the sysctl
system call.
§Example: Get value
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos", target_os = "freebsd"))]
const CTLNAME: &str = "kern.ostype";
#[cfg(any(target_os = "linux", target_os = "android"))]
const CTLNAME: &str = "kernel.ostype";
let ctl = sysctl::Ctl::new(CTLNAME).unwrap();
let desc = ctl.description().unwrap();
println!("Description: {}", desc);
let val = ctl.value().unwrap();
println!("Value: {}", val);
// On Linux all sysctls are String type. Use the following for
// cross-platform compatibility:
let str_val = ctl.value_string().unwrap();
println!("String value: {}", str_val);
§Example: Get value as struct
// Not available on Linux
#[derive(Debug, Default)]
#[repr(C)]
struct ClockInfo {
hz: libc::c_int, /* clock frequency */
tick: libc::c_int, /* micro-seconds per hz tick */
spare: libc::c_int,
stathz: libc::c_int, /* statistics clock frequency */
profhz: libc::c_int, /* profiling clock frequency */
}
let val: Box<ClockInfo> = sysctl::Ctl::new("kern.clockrate").unwrap().value_as().unwrap();
println!("{:?}", val);
Structs§
- CtlFlags
- CtlInfo
- A structure representing control metadata
- CtlIter
- An iterator over Sysctl entries.
- Temperature
- A custom type for temperature sysctls.
Enums§
- Ctl
- This struct represents a system control.
- 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 accessors like
as_int()
. - Sysctl
Error
Constants§
- CTLFLAG_
ANYBODY - CTLFLAG_
CAPRD - CTLFLAG_
CAPRW - CTLFLAG_
CAPWR - CTLFLAG_
DORMANT - CTLFLAG_
DYING - CTLFLAG_
DYN - CTLFLAG_
MPSAFE - CTLFLAG_
NOFETCH - CTLFLAG_
PRISON - CTLFLAG_
RD - CTLFLAG_
RDTUN - CTLFLAG_
RW - CTLFLAG_
RWTUN - CTLFLAG_
SECURE - CTLFLAG_
SECUR E1 - CTLFLAG_
SECUR E2 - CTLFLAG_
SECUR E3 - CTLFLAG_
SKIP - CTLFLAG_
STATS - CTLFLAG_
TUN - CTLFLAG_
VNET - CTLFLAG_
WR - CTLMASK_
SECURE - CTLSHIFT_
SECURE - CTLTYPE
- CTLTYPE_
INT - CTLTYPE_
LONG - CTLTYPE_
NODE - CTLTYPE_
OPAQUE - CTLTYPE_
S8 - CTLTYPE_
S16 - CTLTYPE_
S32 - CTLTYPE_
S64 - CTLTYPE_
STRING - CTLTYPE_
STRUCT - CTLTYPE_
U8 - CTLTYPE_
U16 - CTLTYPE_
U32 - CTLTYPE_
U64 - CTLTYPE_
UINT - CTLTYPE_
ULONG - CTL_
MAXNAME