Crate sysctl [] [src]

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 = "kern.osrevision";

    let d: String = sysctl::description(ctl).unwrap();
    println!("Description: {:?}", d);

    let val_enum = sysctl::value(ctl).unwrap();
    if let sysctl::CtlValue::Int(val) = val_enum {
        println!("Value: {}", val);
    }
}
#[cfg(target_os = "macos")]
fn main() {

    let ctl = "kern.osrevision";

    let val_enum = sysctl::value(ctl).unwrap();
    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

Temperature

A custom type for temperature sysctls.

Enums

CtlValue

An Enum that holds all values returned by sysctl calls. Extract inner value with if let or match.

Constants

CTLFLAG_ANYBODY
CTLFLAG_CAPRD
CTLFLAG_CAPRW
CTLFLAG_CAPWR
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

Functions

description

Returns a result containing the sysctl description if success, the errno caused by sysctl() as string if failure.

set_value

Sets the value of a sysctl. Fetches and returns the new value if successful, errno string if failure.

value

Takes the name of the OID as argument and returns a result containing the sysctl value if success, the errno caused by sysctl() as string if failure.

value_as

A generic function that takes a string as argument and returns a result containing the sysctl value if success, the errno caused by sysctl() as string if failure.

value_oid

Takes an OID as argument and returns a result containing the sysctl value if success, the errno caused by sysctl() as string if failure.

value_oid_as

A generic function that takes an OID as argument and returns a result containing the sysctl value if success, the errno caused by sysctl() as string if failure.