Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ targets = [

[dependencies]
enum-as-inner = "0.6.0"
libc = "^0.2.34"
libc = "^0.2.179"
byteorder = "^1.4.3"
thiserror = "^2.0"
bitflags = "^2"
Expand Down
2 changes: 1 addition & 1 deletion examples/set_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extern crate sysctl;
// Import the trait
use sysctl::Sysctl;

#[cfg(target_os = "freebsd")]
#[cfg(any(target_os = "freebsd", target_os = "openbsd"))]
const CTLNAME: &str = "net.inet.ip.forwarding";

#[cfg(target_os = "macos")]
Expand Down
2 changes: 1 addition & 1 deletion examples/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern crate sysctl;
// Import the trait
use sysctl::Sysctl;

#[cfg(any(target_os = "macos", target_os = "freebsd"))]
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "openbsd"))]
const CTLNAMES: &[&str] = &["kern.ostype"];

#[cfg(any(target_os = "linux", target_os = "android"))]
Expand Down
2 changes: 1 addition & 1 deletion examples/value_as.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl std::fmt::Debug for LoadAvg {
}
}

#[cfg(any(target_os = "macos", target_os = "freebsd"))]
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "openbsd"))]
fn main() {
// Generic type to pass to function will be inferred if not specified on RHS
println!("Read sysctl kern.clockrate as struct directly");
Expand Down
2 changes: 1 addition & 1 deletion examples/value_oid_as.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct ClockInfo {
profhz: libc::c_int, /* profiling clock frequency */
}

#[cfg(any(target_os = "macos", target_os = "freebsd"))]
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "openbsd"))]
fn main() {
let oid: Vec<i32> = vec![libc::CTL_KERN, libc::KERN_CLOCKRATE];
let val: Box<ClockInfo> = sysctl::Ctl::Oid(oid).value_as().expect("could not get value");
Expand Down
2 changes: 1 addition & 1 deletion examples/value_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extern crate sysctl;
// Import the trait
use sysctl::Sysctl;

#[cfg(any(target_os = "macos", target_os = "freebsd"))]
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "openbsd"))]
const CTLNAMES: &[&str] = &["kern.osrevision"];

// On Linux all sysctl are String so it doesn't really make any sense to read an integer value here...
Expand Down
2 changes: 2 additions & 0 deletions src/ctl_flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ bitflags! {
}
}

#[cfg(not(all(test, target_os = "openbsd")))]
#[cfg(test)]
mod tests {
use crate::Sysctl;

#[cfg(not(all(test, target_os = "openbsd")))]
#[test]
fn ctl_flags() {
// This sysctl should be read-only.
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! A simplified interface to the `sysctl` system call.
//!
//! # Example: Get value
//! ```
//! ```ignore-openbsd
//! # use sysctl::Sysctl;
//! #[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos", target_os = "freebsd"))]
//! const CTLNAME: &str = "kern.ostype";
Expand All @@ -23,7 +23,7 @@
//!
//! # Example: Get value as struct
//! ```
//! // Not available on Linux
//! // Not available on Linux and OpenBSD
//! # use sysctl::Sysctl;
//! #[derive(Debug, Default)]
//! #[repr(C)]
Expand Down Expand Up @@ -54,7 +54,7 @@ extern crate walkdir;
#[path = "linux/mod.rs"]
mod sys;

#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos", target_os = "freebsd"))]
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos", target_os = "freebsd", target_os = "openbsd"))]
#[path = "unix/mod.rs"]
mod sys;

Expand Down
13 changes: 7 additions & 6 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub trait Sysctl {
/// ```
///
/// If the sysctl does not exist, `Err(SysctlError::NotFound)` is returned.
/// ```
/// ```ignore-openbsd
/// # use sysctl::Sysctl;
/// #
/// let ctl = sysctl::Ctl::new("this.sysctl.does.not.exist");
Expand All @@ -47,7 +47,7 @@ pub trait Sysctl {
/// ```
///
/// If the sysctl does not exist, `Err(SysctlError::NotFound)` is returned.
/// ```
/// ```ignore-openbsd
/// # use sysctl::{CtlType, Sysctl};
/// #
/// let ctl = sysctl::Ctl::new_with_type("this.sysctl.does.not.exist", CtlType::String, "");
Expand All @@ -65,7 +65,7 @@ pub trait Sysctl {
/// SysctlError on failure.
///
/// # Example
/// ```
/// ```ignore-openbsd
/// # use sysctl::Sysctl;
/// if let Ok(ctl) = sysctl::Ctl::new("kern.ostype") {
/// assert_eq!(ctl.name().unwrap(), "kern.ostype");
Expand All @@ -78,7 +78,7 @@ pub trait Sysctl {
///
/// # Example
///
/// ```
/// ```ignore-openbsd
/// # use sysctl::Sysctl;
/// if let Ok(ctl) = sysctl::Ctl::new("kern.ostype") {
/// let value_type = ctl.value_type().unwrap();
Expand Down Expand Up @@ -192,7 +192,7 @@ pub trait Sysctl {
/// or a SysctlError on failure.
///
/// # Example
/// ```
/// ```ignore-openbsd
/// # use sysctl::Sysctl;
/// if let Ok(ctl) = sysctl::Ctl::new("kern.ostype") {
/// let readable = ctl.flags().unwrap().contains(sysctl::CtlFlags::RD);
Expand All @@ -208,9 +208,10 @@ pub trait Sysctl {
/// or a SysctlError on failure.
///
/// # Example
/// ```
/// ```ignore-openbsd
/// use sysctl::Sysctl;
///
///#[cfg(not(all(test, target_os = "openbsd")))]
/// fn main() {
/// if let Ok(ctl) = sysctl::Ctl::new("kern.osrevision") {
/// let info = ctl.info().unwrap();
Expand Down
26 changes: 13 additions & 13 deletions src/unix/ctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl Sysctl for Ctl {
}
}

#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos")))]
#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos", target_os = "openbsd")))]
fn value_type(&self) -> Result<CtlType, SysctlError> {
match self {
Ctl::Oid(oid) => {
Expand All @@ -73,7 +73,7 @@ impl Sysctl for Ctl {
}
}

#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos"))]
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos", target_os = "openbsd"))]
fn value_type(&self) -> Result<CtlType, SysctlError> {
match self {
Ctl::Oid(oid) => {
Expand Down Expand Up @@ -105,24 +105,24 @@ impl Sysctl for Ctl {
}
}

#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos")))]
#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos", target_os = "openbsd")))]
fn description(&self) -> Result<String, SysctlError> {
let oid = self.oid().ok_or(SysctlError::MissingImplementation)?;
oid2description(oid)
}

#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos"))]
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos", target_os = "openbsd"))]
fn description(&self) -> Result<String, SysctlError> {
Ok("[N/A]".to_string())
}

#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos")))]
#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos", target_os = "openbsd")))]
fn value(&self) -> Result<CtlValue, SysctlError> {
let oid = self.oid().ok_or(SysctlError::MissingImplementation)?;
value_oid(oid)
}

#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos"))]
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos", target_os = "openbsd"))]
fn value(&self) -> Result<CtlValue, SysctlError> {
match self {
Ctl::Oid(oid) => {
Expand All @@ -135,7 +135,7 @@ impl Sysctl for Ctl {
}
}

#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos")))]
#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos", target_os = "openbsd")))]
fn value_as<T>(&self) -> Result<Box<T>, SysctlError> {
let oid = self.oid().ok_or(SysctlError::MissingImplementation)?;
value_oid_as::<T>(oid)
Expand All @@ -145,7 +145,7 @@ impl Sysctl for Ctl {
self.value().map(|v| format!("{}", v))
}

#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos"))]
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos", target_os = "openbsd"))]
fn value_as<T>(&self) -> Result<Box<T>, SysctlError> {
match self {
Ctl::Oid(oid) => {
Expand All @@ -158,13 +158,13 @@ impl Sysctl for Ctl {
}
}

#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos")))]
#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos", target_os = "openbsd")))]
fn set_value(&self, value: CtlValue) -> Result<CtlValue, SysctlError> {
let oid = self.oid().ok_or(SysctlError::MissingImplementation)?;
set_oid_value(&oid, value)
}

#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos"))]
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos", target_os = "openbsd"))]
fn set_value(&self, value: CtlValue) -> Result<CtlValue, SysctlError> {
match self {
Ctl::Oid(oid) => {
Expand All @@ -177,7 +177,7 @@ impl Sysctl for Ctl {
}
}

#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos")))]
#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos", target_os = "openbsd")))]
fn set_value_string(&self, value: &str) -> Result<String, SysctlError> {
let oid = self.oid().ok_or(SysctlError::MissingImplementation)?;
let ctl_type = self.value_type()?;
Expand All @@ -204,7 +204,7 @@ impl Sysctl for Ctl {
self.value_string()
}

#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos"))]
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos", target_os = "openbsd"))]
fn set_value_string(&self, value: &str) -> Result<String, SysctlError> {
let ctl_type = self.value_type()?;

Expand Down Expand Up @@ -303,7 +303,7 @@ mod tests {
#[cfg(target_os = "freebsd")]
assert_eq!(descp, "Operating system type");

#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos", target_os = "linux"))]
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos", target_os = "linux", target_os = "openbsd"))]
assert_eq!(descp, "[N/A]");
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/unix/ctl_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl Iterator for CtlIter {
///
/// # Example
///
/// ```
/// ```ignore-openbsd
/// use sysctl::Sysctl;
///
/// let kern = sysctl::Ctl::new("kern");
Expand All @@ -75,6 +75,7 @@ impl IntoIterator for Ctl {
}
}

#[cfg(not(all(test, target_os = "openbsd")))]
#[cfg(test)]
mod tests {
use crate::Sysctl;
Expand Down
Loading