#![crate_name = "sysinfo"]
#![crate_type = "lib"]
#![crate_type = "rlib"]
#![deny(missing_docs)]
#![deny(broken_intra_doc_links)]
#![allow(unknown_lints)]
#[macro_use]
extern crate cfg_if;
#[cfg(not(any(target_os = "unknown", target_arch = "wasm32")))]
extern crate libc;
#[cfg(feature = "multithread")]
extern crate rayon;
#[macro_use]
extern crate doc_comment;
extern crate once_cell;
#[cfg(doctest)]
doctest!("../README.md");
#[cfg(feature = "debug")]
#[doc(hidden)]
macro_rules! sysinfo_debug {
($($x:tt)*) => {{
eprintln!($($x)*);
}}
}
#[cfg(not(feature = "debug"))]
#[doc(hidden)]
macro_rules! sysinfo_debug {
($($x:tt)*) => {{}};
}
cfg_if! {
if #[cfg(any(target_os = "macos", target_os = "ios"))] {
mod apple;
use apple as sys;
extern crate core_foundation_sys;
#[cfg(test)]
const MIN_USERS: usize = 1;
} else if #[cfg(windows)] {
mod windows;
use windows as sys;
extern crate winapi;
extern crate ntapi;
#[cfg(test)]
const MIN_USERS: usize = 1;
} else if #[cfg(any(target_os = "linux", target_os = "android"))] {
mod linux;
use linux as sys;
#[cfg(test)]
const MIN_USERS: usize = 1;
} else {
mod unknown;
use unknown as sys;
#[cfg(test)]
const MIN_USERS: usize = 0;
}
}
pub use common::{
AsU32, DiskType, DiskUsage, LoadAvg, NetworksIter, Pid, RefreshKind, Signal, User,
};
pub use sys::{Component, Disk, NetworkData, Networks, Process, ProcessStatus, Processor, System};
pub use traits::{
ComponentExt, DiskExt, NetworkExt, NetworksExt, ProcessExt, ProcessorExt, SystemExt, UserExt,
};
#[cfg(feature = "c-interface")]
pub use c_interface::*;
pub use utils::get_current_pid;
#[cfg(feature = "c-interface")]
mod c_interface;
mod common;
mod debug;
mod system;
mod traits;
mod utils;
pub fn set_open_files_limit(mut _new_limit: isize) -> bool {
#[cfg(any(target_os = "linux", target_os = "android"))]
{
if _new_limit < 0 {
_new_limit = 0;
}
let max = sys::system::get_max_nb_fds();
if _new_limit > max {
_new_limit = max;
}
if let Ok(ref mut x) = unsafe { sys::system::REMAINING_FILES.lock() } {
let diff = max - **x;
**x = _new_limit - diff;
true
} else {
false
}
}
#[cfg(all(not(target_os = "linux"), not(target_os = "android")))]
{
false
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn check_memory_usage() {
let mut s = ::System::new();
s.refresh_all();
assert_eq!(
s.get_processes()
.iter()
.all(|(_, proc_)| proc_.memory() == 0),
false
);
}
#[test]
fn check_users() {
let mut s = ::System::new();
assert!(s.get_users().is_empty());
s.refresh_users_list();
assert!(s.get_users().len() >= MIN_USERS);
let mut s = ::System::new();
assert!(s.get_users().is_empty());
s.refresh_all();
assert!(s.get_users().is_empty());
let s = ::System::new_all();
assert!(s.get_users().len() >= MIN_USERS);
}
#[test]
fn check_system_info() {
if MIN_USERS > 0 {
let s = ::System::new();
assert!(!s.get_name().expect("Failed to get system name").is_empty());
assert!(!s
.get_version()
.expect("Failed to get system version")
.is_empty());
}
}
#[test]
fn check_host_name() {
if MIN_USERS > 0 {
let s = ::System::new();
assert!(!s
.get_host_name()
.expect("Failed to get host name")
.is_empty());
}
}
}
#[cfg(doctest)]
doc_comment!(
"
```
fn is_send<T: Send>() {}
is_send::<sysinfo::System>();
```
```
fn is_sync<T: Sync>() {}
is_sync::<sysinfo::System>();
```"
);