Crate sysctl[][src]

A simplified interface to the sysctl system call.

Example: Get value

#[cfg(any(target_os = "macos", 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: {}", 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

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 if let or match.

SysctlError

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_SECURE1
CTLFLAG_SECURE2
CTLFLAG_SECURE3
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

Traits

Sysctl