7 releases

0.3.0 Jan 7, 2019
0.2.0 May 28, 2018
0.1.4 Jan 4, 2018
0.1.2 May 23, 2017

#7 in Operating systems

Download history 764/week @ 2018-11-11 575/week @ 2018-11-18 1151/week @ 2018-11-25 1145/week @ 2018-12-02 1153/week @ 2018-12-09 862/week @ 2018-12-16 699/week @ 2018-12-23 879/week @ 2018-12-30 955/week @ 2019-01-06 925/week @ 2019-01-13 909/week @ 2019-01-20 1253/week @ 2019-01-27 994/week @ 2019-02-03 996/week @ 2019-02-10 1362/week @ 2019-02-17

3,708 downloads per month
Used in 9 crates (7 directly)

MIT license

1.5MB
1K SLoC

This crate provides a safe interface for reading and writing information to the kernel using the sysctl interface.

Current Version

FreeBSD and macOS are supported.
Contributions for improvements and other platforms are welcome.

Documentation

Documentation is available here: https://johalun.github.io/sysctl-rs/

or, to generate documentation locally do:

$ git clone https://github.com/johalun/sysctl-rs && cd sysctl-rs
$ cargo doc --no-deps
$ firefox target/doc/sysctl/index.html

Usage

Add to Cargo.toml

[dependencies]
sysctl = "0.3.0"

macos

  • Due to limitations in the sysctl(3) API, many of the methods of the Ctl take a mutable reference to self on macos.
  • Sysctl descriptions are not available on macos.
  • Some tests failures are ignored, as the respective sysctls do not exist on macos.

Example

sysctl comes with several examples, see the examples folder:

  • value.rs: shows how to get a sysctl value
  • value_as.rs: parsing values as structures
  • value_oid_as.rs: getting a sysctl from OID constants from the libc crate.
  • set_value.rs: shows how to set a sysctl value
  • struct.rs: reading data into a struct
  • temperature.rs: parsing temperatures
  • iterate.rs: showcases iteration over the sysctl tree

Run with:

$ cargo run --example iterate

Or in a separate crate:

extern crate sysctl;
use sysctl::{Ctl, CtlValue};

fn main() {
    let ctl = Ctl::new("kern.osrevision");
    println!("Description: {:?}", ctl.description().unwrap());

    let val_enum = ctl.value().unwrap();
    if let CtlValue::Int(val) = val_enum {
        println!("Value: {}", val);
    }
}

Dependencies