Giter Site home page Giter Site logo

sys-info-rs's Introduction

sys-info-rs

Build Status

Get system information in Rust.

For now it supports Linux, Mac OS X, illumos, Solaris, FreeBSD, OpenBSD, NetBSD and Windows. And now it can get information of kernel/cpu/memory/disk/load/hostname and so on.

Documentation

Usage

Add this to Cargo.toml:

[dependencies]
sys-info = "0.9"

and add this to crate root:

extern crate sys_info;

sys-info-rs's People

Contributors

alovchin91 avatar badboy avatar bnoordhuis avatar botovq avatar davidkna avatar fillzpp avatar fraggerfox avatar gum-joe avatar hoverbear avatar hvenev avatar ignatenkobrain avatar jclulow avatar jessicah avatar jg1uaa avatar jot85 avatar kostikbel avatar lion328 avatar lonami avatar lwhsu avatar mehcode avatar mikeumus avatar ostrosco avatar pajowu avatar rich-murphey avatar rneswold avatar seth-priya avatar sitischu avatar theduke avatar yadominjinta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

sys-info-rs's Issues

error occurred: Failed to find tool. Is `aarch64-linux-gnu-gcc` installed?

I am compling sys info from windows to arm64, I found the following error:

PS G:\2.Codingx\TEST\testlinux> cargo build --release --target aarch64-unknown-linux-gnu
Compiling libc v0.2.139
Compiling cc v1.0.78
Compiling sys-info v0.9.1
error: failed to run custom build command for sys-info v0.9.1

Caused by:
process didn't exit successfully: G:\2.Codingx\TEST\testlinux\target\release\build\sys-info-bb6b5d424202c977\build-script-build (exit code: 1)
--- stdout
TARGET = Some("aarch64-unknown-linux-gnu")
OPT_LEVEL = Some("3")
HOST = Some("x86_64-pc-windows-msvc")
cargo:rerun-if-env-changed=CC_aarch64-unknown-linux-gnu
CC_aarch64-unknown-linux-gnu = None
cargo:rerun-if-env-changed=CC_aarch64_unknown_linux_gnu
CC_aarch64_unknown_linux_gnu = None
cargo:rerun-if-env-changed=TARGET_CC
TARGET_CC = None
cargo:rerun-if-env-changed=CC
CC = None
RUSTC_LINKER = Some("G:\Program Files (x86)\Arm GNU Toolchain aarch64-none-linux-gnu\12.2 rel1\bin\aarch64-none-linux-gnu-gcc")
cargo:rerun-if-env-changed=CROSS_COMPILE
CROSS_COMPILE = None
cargo:rerun-if-env-changed=CFLAGS_aarch64-unknown-linux-gnu
CFLAGS_aarch64-unknown-linux-gnu = None
cargo:rerun-if-env-changed=CFLAGS_aarch64_unknown_linux_gnu
CFLAGS_aarch64_unknown_linux_gnu = None
cargo:rerun-if-env-changed=TARGET_CFLAGS
TARGET_CFLAGS = None
cargo:rerun-if-env-changed=CFLAGS
CFLAGS = None
cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("false")
CARGO_CFG_TARGET_FEATURE = Some("neon")
running: "aarch64-linux-gnu-gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-Wall" "-Wextra" "-o" "G:\2.Codingx\TEST\testlinux\target\aarch64-unknown-linux-gnu\release\build\sys-info-acfd68cc9c785b8d\out\c/linux.o" "-c" "c/linux.c"

--- stderr

error occurred: Failed to find tool. Is aarch64-linux-gnu-gcc installed? (see https://github.com/rust-lang/cc-rs#compile-time-requirements for help)

Memory unsafety: data races in darwin.c

I've found the following data races in darwin.c:

  1. The static unsigned long long size is a mutable global that is read/modified without any synchronization.
    • static unsigned long long size = 0;
    • It looks like this is meant to be an optimization but it is unsound since it is called directly from the public Rust function mem_info(). Multiple Rust threads could racily write to the global variable size.
  2. static int skipvfs is mutable global that is racily initizialized in makevfslist().
    • static int skipvfs;
    • disk_info() is a public Rust function that can be directly called from safe Rust code

Making get_cpu_speed architecture-independent on Windows

Hi all!

I've been experimenting with the aarch64-pc-windows-msvc target on a Surface Pro X recently and I came across this bug:

For windows the code to get_cpu_speed uses the Intel-specific __rdtsc intrinsic, which doesn't even compile for ARM-based Windows.

To fix this I can see two ways:

a)
I believe _ReadStatusReg (ARM64_PMCCNTR_EL0) would be a drop-in replacement for __rdtsc (it compiles fine and gives me a value of 2997 Mhz on my 3GHz Surface Pro X, which is ok?).
So maybe that would be a if target.contains(xx) {.define(xx)} in build.rs which will then pass a -Dmacro to the C file and use that to change between different #define definitions.

b)
Or the cleaner solution of finding an arch-independent way of doing this (I don't know what it would be yet, hence opening this as an issue rather than a PR!)

I guess there's also a discussion to be had on if get_cpu_speed is meant to give an instantaneous reading vs the "advertised speed"/base clock/Turboboost Max?
I see for Linux we're looking at /proc/cpuinfo, whereas for windows we're trying to calculate it based on the cycle counter (so both are instantaneous readings).

Does anyone with more Windows experience have any other ideas on how to get the data? (surely Windows reports the instantaneous Mhz to somewhere... But I haven't found it yet!)

Question regarding support for V1 and 2 of PSAPI in windows.c

I am not completely sure how to go about detecting the version of PSAPI that is being linked against for c/windows.c but while cross compiling with mingw64 on ubuntu 16.04. It apprarently links to version 2 which does not have a definition of EnumProcesses, it has K32EnumProcesses instead. The following is the output I get when I try to use the sys-info crate with EnumProcesses when cross compiled with mingw64:

error: linking with /usr/bin/x86_64-w64-mingw32-gcc failed: exit code: 1
note: "/usr/bin/x86_64-w64-mingw32-gcc" "-Wl,--enable-long-section-names" "-fno-use-linker-plugin" "-Wl,--nxcompat" "-nostdlib" "-m64" "/home/ajohnson/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_6
4-pc-windows-gnu/lib/crt2.o" "/home/ajohnson/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/rsbegin.o" "-L" "/home/ajohnson/.multirust/toolchains/stable-x86_64-unknown-linux-gnu
/lib/rustlib/x86_64-pc-windows-gnu/lib" "/home/ajohnson/github/ajces/ajces-client/rust-client/target/x86_64-pc-windows-gnu/debug/rust_client.0.o" "-o" "/home/ajohnson/github/ajces/ajces-client/rust-client/target/x86_64-pc-
windows-gnu/debug/rust_client.exe" "-Wl,--gc-sections" "-nodefaultlibs" "-L" "/home/ajohnson/github/ajces/ajces-client/rust-client/target/x86_64-pc-windows-gnu/debug" "-L" "/home/ajohnson/github/ajces/ajces-client/rust-cli
ent/target/x86_64-pc-windows-gnu/debug/deps" "-L" "/home/ajohnson/github/ajces/ajces-client/rust-client/target/x86_64-pc-windows-gnu/debug/build/sys-info-d4d4ee5c057893c4/out" "-L" "/home/ajohnson/github/ajces/ajces-client
/rust-client/target/x86_64-pc-windows-gnu/debug/build/rust-crypto-1afef890e2a253bd/out" "-L" "/home/ajohnson/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib" "-Wl,-Bstatic" "-Wl,
-Bdynamic" "/home/ajohnson/github/ajces/ajces-client/rust-client/target/x86_64-pc-windows-gnu/debug/deps/libfiletime-c297f1d53d29af71.rlib" "/home/ajohnson/github/ajces/ajces-client/rust-client/target/x86_64-pc-windows-gnu
/debug/deps/libcrypto-b53f4f52658d6577.rlib" "/home/ajohnson/github/ajces/ajces-client/rust-client/target/x86_64-pc-windows-gnu/debug/deps/librustc_serialize-3bc953984ed46e7f.rlib" "/home/ajohnson/github/ajces/ajces-client
/rust-client/target/x86_64-pc-windows-gnu/debug/deps/libtime-71756e48b8b5b73b.rlib" "/home/ajohnson/github/ajces/ajces-client/rust-client/target/x86_64-pc-windows-gnu/debug/deps/librand-c724acb3942597d1.rlib" "/home/ajohns
on/github/ajces/ajces-client/rust-client/target/x86_64-pc-windows-gnu/debug/deps/liblibc-87e81dcd3af1ebe2.rlib" "/home/ajohnson/github/ajces/ajces-client/rust-client/target/x86_64-pc-windows-gnu/debug/deps/libkernel32-7579
37e2863677bb.rlib" "/home/ajohnson/github/ajces/ajces-client/rust-client/target/x86_64-pc-windows-gnu/debug/deps/libwinapi-eb43423579d03730.rlib" "/home/ajohnson/github/ajces/ajces-client/rust-client/target/x86_64-pc-windo
ws-gnu/debug/deps/libsys_info-2fd68968db155881.rlib" "/home/ajohnson/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/libstd-d16b8f0e.rlib" "/home/ajohnson/.multirust/toolchains/s
table-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/libcollections-d16b8f0e.rlib" "/home/ajohnson/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/librustc_unicod
e-d16b8f0e.rlib" "/home/ajohnson/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/librand-d16b8f0e.rlib" "/home/ajohnson/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/
rustlib/x86_64-pc-windows-gnu/lib/liballoc-d16b8f0e.rlib" "/home/ajohnson/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/liballoc_system-d16b8f0e.rlib" "/home/ajohnson/.multirus
t/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/liblibc-d16b8f0e.rlib" "/home/ajohnson/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/libcore-
d16b8f0e.rlib" "-l" "advapi32" "-l" "kernel32" "-l" "gcc_eh" "-l" "ws2_32" "-l" "userenv" "-l" "shell32" "-l" "advapi32" "-l" "compiler-rt" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-luser32" "-lkernel32" "/home/ajohnson
/.multirust/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/rsend.o"
note: /home/ajohnson/github/ajces/ajces-client/rust-client/target/x86_64-pc-windows-gnu/debug/deps/libsys_info-2fd68968db155881.rlib(windows.o): In function get_proc_total': /home/ajohnson/github/sys-info-rs/c/windows.c:81: undefined reference toEnumProcesses'
collect2: error: ld returned 1 exit status

There probably needs to be an IFDEF somewhere that covers checking the PSAPI version that is being linked but I don't know off the top of my head what to test.

I realize this is probably not a big priority.

Thanks for the great crate!

unreachable expression

This warning is printed during the build of the starship project:

warning: unreachable expression
   --> /wrkdirs/usr/ports/shells/starship/work/starship-1.4.0/cargo-crates/sys-info-0.9.1/lib.rs:857:5
    |
838 |                 return Err(Error::IO(io::Error::last_os_error()));
    |                 ------------------------------------------------- any code following this expression is unreachable
...
857 |     Err(Error::UnsupportedSystem)
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unreachable expression
    |
note: the lint level is defined here
   --> /wrkdirs/usr/ports/shells/starship/work/starship-1.4.0/cargo-crates/sys-info-0.9.1/lib.rs:856:12
    |
856 |     #[warn(unreachable_code)]
    |            ^^^^^^^^^^^^^^^^

warning: `sys-info` (lib) generated 1 warning

The wrong version is returned in the iOS simulator

@andrewgAB wrote in private correspondence:

The sysctl call that is used by that crate doesn’t return the right values for the iOS Simulator.

Right now it’s reporting MacOS version 19.4.0 (the Darwin kernel version) rather than the macOS version.

It is often more useful to know the iOS/macOS version than the kernel version. sys_info::os_release should return the operating system version instead of the kernel version.

Does not compile on non-x86

error[E0308]: mismatched types
   --> lib.rs:398:34
    |
398 |             if libc::gethostname(buf.as_mut_ptr() as *mut i8, buf_size) < 0 {
    |                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u8`, found `i8`
    |
    = note: expected raw pointer `*mut u8`
               found raw pointer `*mut i8`
error[E0308]: mismatched types
   --> lib.rs:401:46
    |
401 |             let hostname_len = libc::strnlen(buf.as_ptr() as *const i8, buf_size);
    |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u8`, found `i8`
    |
    = note: expected raw pointer `*const u8`
               found raw pointer `*const i8`

0.7.0 build failure on AArch64

You can see the failed run here https://github.com/rbtcollins/effective-limits.rs/pull/9/checks?check_run_id=820016011:

(and the github action config there might be useful, if you want CI coverage of more platforms)

   Compiling sys-info v0.7.0
error[E0308]: mismatched types
   --> /cargo/registry/src/github.com-1ecc6299db9ec823/sys-info-0.7.0/lib.rs:618:22
    |
618 | pub fn boottime() -> Result<timeval, Error> {
    |        --------      ^^^^^^^^^^^^^^^^^^^^^^ expected enum `std::result::Result`, found `()`
    |        |
    |        implicitly returns `()` as its body has no tail or `return` expression
    |
    = note:   expected enum `std::result::Result<libc::timeval, Error>`
            found unit type `()`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
The following warnings were emitted during compilation:

warning: c/linux.c:42:9: warning: implicit declaration of function 'get_nprocs' is invalid in C99 [-Wimplicit-function-declaration]
warning:         return get_nprocs();
warning:                ^
warning: c/linux.c:96:11: warning: implicitly declaring library function 'index' with type 'char *(const char *, int)' [-Wimplicit-function-declaration]
warning:                 mount = index(procline, ' ');
warning:                         ^
warning: c/linux.c:96:11: note: include the header <strings.h> or explicitly provide a declaration for 'index'

unify all `LinuxOSReleaseInfo` id to lowercase

the documentation of that struct states the id as "A lower-case string", however, it is not a lowercase string on some distro such as openEuler.

output of debug printing:

Ok(
    LinuxOSReleaseInfo {
        id: Some(
            "openEuler",
        ),
        id_like: None,
        name: Some(
            "openEuler",
        ),
        pretty_name: Some(
            "openEuler 20.03 (LTS-SP1)",
        ),
        version: Some(
            "20.03 (LTS-SP1)",
        ),
        version_id: Some(
            "20.03",
        ),
        ...
    },
)

x86_64-pc-windows-gnu build fails on Ubuntu 20 #724

Target: x86_64-pc-windows-gnu

error: failed to run custom build command for `sys-info v0.8.0`

Caused by:
  process didn't exit successfully: `/github/workspace/./target/release/build/sys-info-215e09fdcb498047/build-script-build` (exit status: 1)
  --- stdout
  cargo:rustc-flags=-l psapi
  cargo:rustc-flags=-l powrprof
  TARGET = Some("x86_64-pc-windows-gnu")
  OPT_LEVEL = Some("3")
  HOST = Some("x86_64-unknown-linux-musl")
  CC_x86_64-pc-windows-gnu = None
  CC_x86_64_pc_windows_gnu = None
  TARGET_CC = None
  CC = None
  CROSS_COMPILE = None
  CFLAGS_x86_64-pc-windows-gnu = None
  CFLAGS_x86_64_pc_windows_gnu = None
  TARGET_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("false")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
  running: "x86_64-w64-mingw32-gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-m64" "-Wall" "-Wextra" "-o" "/github/workspace/./target/x86_64-pc-windows-gnu/release/build/sys-info-644b5c109f2cf0ca/out/c/windows.o" "-c" "c/windows.c"
  cargo:warning=c/windows.c:6:10: fatal error: powerbase.h: No such file or directory
  cargo:warning=    6 | #include <powerbase.h>
  cargo:warning=      |          ^~~~~~~~~~~~~
  cargo:warning=compilation terminated.
  exit status: 1

Compile time errors on partially supported systems

At the moment, the behaviour on partially systems is to return Err(Error::UnsupportedSystem). This error is therefore raised at runtime. If an error can be known at compile time, surely that's a better place to raise it?

I propose changing the design so that functions are only included for a system if they are supported on that system.

linux_os_release is a good example; it's only supported on Linux and yet any platform can call it, with the result always being Err(Error::UnsupportedSystem). An alternative approach would be to only compile linux_os_release on Linux systems so that trying to use it results in an error at compile time.

Another example would be os_release or cpu_speed, which aren't supported on Android.

In addition, on systems like iOS, which aren't formally supported, there are build errors - which isn't a great way to error out. Moreover, some functions, such as hostname are valid for all unix-like systems and so could be compiled for iOS (I can't test this claim). Not including functions that will cause errors means that someone can get the most out of the library on any system.

I'm happy to make these changes myself, I was wondering what other peoples thoughts were on such a change before I spent time working on it.

Thanks!

compiling for windows

Hi,

Trying to compile version 0.5.9 for x86_64-pc-windows-gnu fails.

error[E0425]: cannot find function sysconf in crate libc
--> /cargo/registry/src/github.com-1ecc6299db9ec823/sys-info-0.5.9/lib.rs:396:34
|
396 | let buf_size = libc::sysconf(libc::_SC_HOST_NAME_MAX) as usize;
| ^^^^^^^ not found in libc

error[E0425]: cannot find value _SC_HOST_NAME_MAX in crate libc
--> /cargo/registry/src/github.com-1ecc6299db9ec823/sys-info-0.5.9/lib.rs:396:48
|
396 | let buf_size = libc::sysconf(libc::_SC_HOST_NAME_MAX) as usize;
| ^^^^^^^^^^^^^^^^^ not found in libc

error[E0425]: cannot find function gethostname in crate libc
--> /cargo/registry/src/github.com-1ecc6299db9ec823/sys-info-0.5.9/lib.rs:398:22
|
398 | if libc::gethostname(buf.as_mut_ptr() as *mut i8, buf_size) < 0 {
| ^^^^^^^^^^^ help: a function with a similar name exists: getsockname

error: aborting due to 3 previous errors

Version 0.5.8 works fine.

Amir

Build fail for riscv64 due to test case with cpu_speed()

Hi,
From Debian rust sys-info package which FBTFS fail:
https://buildd.debian.org/status/package.php?p=rust-sys-info&suite=sid
I submit a patch to pass the tests case:
https://salsa.debian.org/rust-team/debcargo-conf/-/merge_requests/295
But It seems very suboptimally.
So what is the best solution for such case?
The /proc/cpuinfo is below:

root@unmatched-local:~/git/debcargo-conf/src/sys-info/debian# cat /proc/cpuinfo processor       : 0 hart            : 1 isa             : rv64imafdc mmu             : sv39 uarch           : sifive,bullet0  processor       : 1 hart            : 2 isa             : rv64imafdc mmu             : sv39 uarch           : sifive,bullet0  processor       : 2 hart            : 3 isa             : rv64imafdc mmu             : sv39 uarch           : sifive,bullet0  processor       : 3 hart            : 4 isa             : rv64imafdc mmu             : sv39 uarch           : sifive,bullet0

If no other options, I will send RP to pass the case that is the same patch for Debian.

LibreSSL version on OpenBSD

OpenBSD -current is now on 3.3.2:

  OPENSSL_LIB_DIR unset
  cargo:rerun-if-env-changed=X86_64_UNKNOWN_OPENBSD_OPENSSL_INCLUDE_DIR
  X86_64_UNKNOWN_OPENBSD_OPENSSL_INCLUDE_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_INCLUDE_DIR
  OPENSSL_INCLUDE_DIR unset
  cargo:rerun-if-env-changed=X86_64_UNKNOWN_OPENBSD_OPENSSL_DIR
  X86_64_UNKNOWN_OPENBSD_OPENSSL_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_DIR
  OPENSSL_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=OPENSSL_STATIC
  cargo:rerun-if-env-changed=OPENSSL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-openbsd
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_openbsd
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-openbsd
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_openbsd
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-openbsd
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_openbsd
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=SYSROOT
  cargo:rerun-if-env-changed=OPENSSL_STATIC
  cargo:rerun-if-env-changed=OPENSSL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
  cargo:rustc-link-lib=ssl
  cargo:rustc-link-lib=crypto
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-openbsd
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_openbsd
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-openbsd
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_openbsd
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-openbsd
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_openbsd
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  OPT_LEVEL = Some("0")
  TARGET = Some("x86_64-unknown-openbsd")
  HOST = Some("x86_64-unknown-openbsd")
  CC_x86_64-unknown-openbsd = None
  CC_x86_64_unknown_openbsd = None
  HOST_CC = None
  CC = None
  CFLAGS_x86_64-unknown-openbsd = None
  CFLAGS_x86_64_unknown_openbsd = None
  HOST_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
  running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-Wall" "-Wextra" "-E" "build/expando.c"
  exit code: 0
  cargo:rustc-cfg=osslconf="OPENSSL_NO_BUF_FREELISTS"
  cargo:rustc-cfg=osslconf="OPENSSL_NO_COMP"
  cargo:rustc-cfg=osslconf="OPENSSL_NO_KRB5"
  cargo:rustc-cfg=osslconf="OPENSSL_NO_PSK"
  cargo:rustc-cfg=osslconf="OPENSSL_NO_RFC3779"
  cargo:rustc-cfg=osslconf="OPENSSL_NO_SRP"
  cargo:rustc-cfg=osslconf="OPENSSL_NO_SSL3_METHOD"
  cargo:conf=OPENSSL_NO_BUF_FREELISTS,OPENSSL_NO_COMP,OPENSSL_NO_KRB5,OPENSSL_NO_PSK,OPENSSL_NO_RFC3779,OPENSSL_NO_SRP,OPENSSL_NO_SSL3_METHOD
  cargo:rustc-cfg=libressl
  cargo:rustc-cfg=libressl251
  cargo:rustc-cfg=libressl261
  cargo:rustc-cfg=libressl270
  cargo:rustc-cfg=libressl271
  cargo:rustc-cfg=libressl273
  cargo:rustc-cfg=libressl280
  cargo:rustc-cfg=libressl281
  cargo:rustc-cfg=libressl291
  cargo:rustc-cfg=libressl321
  cargo:libressl_version_number=3030200f

  --- stderr
  thread 'main' panicked at '

  This crate is only compatible with OpenSSL 1.0.1 through 1.1.1, or LibreSSL 2.5
  through 3.3.1, but a different version of OpenSSL was found. The build is now aborting
  due to this version mismatch.

Disk Info is not Thread-Safe

I've seen a few segmentation faults when running disk_info() on linux.

If you call disk_info() from multiple threads at once this can core dump:

#5  0x00005585db2e28cc in DFcleanup () at c/linux.c:167
#6  0x00005585db2e265f in get_disk_info () at c/linux.c:117
#7  0x00005585db2cee4a in sys_info::disk_info () at /home/cetra/.cargo/registry/src/github.com-1ecc6299db9ec823/sys-info-0.6.0/lib.rs:494

There is a global DFhashvector:

static struct nlist *DFhashvector[DFHASHSIZE];

Which, if two threads are calling disk_info() the DFCleanup() call at the end of the get_disk_info() function will both try and free at the same time:

sys-info-rs/c/linux.c

Lines 159 to 172 in a5d126d

void DFcleanup()
{
struct nlist *np, *next;
int i;
for (i=0; i<DFHASHSIZE; i++) {
/* Non-standard for loop. Note the last clause happens at the end of the loop. */
for (np = DFhashvector[i]; np; np=next) {
next=np->next;
free(np->name);
free(np);
}
DFhashvector[i] = 0;
}
}

This results in segfaults & also double frees

Build failed due to mismatch type error on android termux

I was trying to build deno from source
Using cargo but sys-info gives
Following error

error[E0308]: mismatched types
   --> /data/data/com.termux/files/home/.cargo/registry/src/github.com-1ecc6299db9ec823/sys-info-0.7.0/lib.rs:618:22
    |
618 | pub fn boottime() -> Result<timeval, Error> {
    |        --------      ^^^^^^^^^^^^^^^^^^^^^^ expected enum `std::result::Result`, found `()`
    |        |
    |        implicitly returns `()` as its body has no tail or `return` expression
    |
    = note:   expected enum `std::result::Result<libc::timeval, Error>`
            found unit type `()`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
The following warnings were emitted during compilation:

warning: c/linux.c:96:11: warning: implicitly declaring library function 'index' with type 'char *(const char *, int)' [-Wimplicit-function-declaration]
warning:                 mount = index(procline, ' ');
warning:                         ^
warning: c/linux.c:96:11: note: include the header <strings.h> or explicitly provide a declaration for 'index'
warning: 1 warning generated.

error: could not compile `sys-info`.

I'm on aarch64

Support container CPU & memory limits

When running within a Docker container it is possible to get information about the CPU and memory limits from /sys/fs/cgroup.

For example /proc/meminfo shows the memory information of the host machine, however /sys/fs/cgroup/memory/memory.limit_in_bytes identifies exactly how much memory this container is allowed to allocate before being killed by the container runtime.

Correspondingly /proc/cpuinfo shows information about all host CPUs, and not the number of cores that the container is limited to.

Examples:

$ docker run --rm -it -m 128m --cpuset-cpus="0-0" alpine:latest cat /proc/meminfo | grep MemTotal
MemTotal:        8165020 kB
$ docker run --rm -it -m 128m --cpuset-cpus="0-0" alpine:latest cat /sys/fs/cgroup/memory/memory.limit_in_bytes
134217728
$ docker run --rm -it -m 128m --cpuset-cpus="0-0" alpine:latest cat /proc/cpuinfo | grep processor
processor	: 0
processor	: 1
$ docker run --rm -it -m 128m --cpuset-cpus="0-0" alpine:latest cat /sys/fs/cgroup/cpuset/cpuset.cpus
0

Build x86_64-pc-windows-gnu target on Linux fails

[lion328@lion328-LINUXPC sys-info-rs]$ cargo build --target=x86_64-pc-windows-gnu
   Compiling libc v0.2.32
   Compiling gcc v0.3.54
   Compiling sys-info v0.5.1 (file:///mnt/40daab41-cd89-4a57-9ae2-95ae141940d9/GitRepos/sys-info-rs)
warning: use of deprecated item
 --> build.rs:5:9
  |
5 |         gcc::compile_library("libinfo.a", &["c/linux.c"]);
  |         ^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(deprecated)] on by default

warning: use of deprecated item
 --> build.rs:7:9
  |
7 |         gcc::compile_library("libinfo.a", &["c/macos.c"]);
  |         ^^^^^^^^^^^^^^^^^^^^

warning: use of deprecated item
 --> build.rs:9:9
  |
9 |         gcc::compile_library("libinfo.a", &["c/windows.c"]);
  |         ^^^^^^^^^^^^^^^^^^^^

error: failed to run custom build command for `sys-info v0.5.1 (file:///mnt/40daab41-cd89-4a57-9ae2-95ae141940d9/GitRepos/sys-info-rs)`
process didn't exit successfully: `/mnt/40daab41-cd89-4a57-9ae2-95ae141940d9/GitRepos/sys-info-rs/target/debug/build/sys-info-3295ef534ba2f7db/build-script-build` (exit code: 101)
--- stdout
TARGET = Some("x86_64-pc-windows-gnu")
OPT_LEVEL = Some("0")
TARGET = Some("x86_64-pc-windows-gnu")
HOST = Some("x86_64-unknown-linux-gnu")
TARGET = Some("x86_64-pc-windows-gnu")
TARGET = Some("x86_64-pc-windows-gnu")
HOST = Some("x86_64-unknown-linux-gnu")
CC_x86_64-pc-windows-gnu = None
CC_x86_64_pc_windows_gnu = None
TARGET_CC = None
CC = None
HOST = Some("x86_64-unknown-linux-gnu")
CROSS_COMPILE = None
TARGET = Some("x86_64-pc-windows-gnu")
HOST = Some("x86_64-unknown-linux-gnu")
CFLAGS_x86_64-pc-windows-gnu = None
CFLAGS_x86_64_pc_windows_gnu = None
TARGET_CFLAGS = None
CFLAGS = None
DEBUG = Some("true")
running: "x86_64-w64-mingw32-gcc" "-O0" "-ffunction-sections" "-fdata-sections" "-g" "-m64" "-Wall" "-Wextra" "-o" "/mnt/40daab41-cd89-4a57-9ae2-95ae141940d9/GitRepos/sys-info-rs/target/x86_64-pc-windows-gnu/debug/build/sys-info-d0550d93732dd07b/out/c/linux.o" "-c" "c/linux.c"
cargo:warning=c/linux.c:4:10: fatal error: sys/sysinfo.h: No such file or directory
cargo:warning= #include <sys/sysinfo.h>
cargo:warning=          ^~~~~~~~~~~~~~~
cargo:warning=compilation terminated.
exit code: 1

--- stderr
thread 'main' panicked at '

Internal error occurred: Command "x86_64-w64-mingw32-gcc" "-O0" "-ffunction-sections" "-fdata-sections" "-g" "-m64" "-Wall" "-Wextra" "-o" "/mnt/40daab41-cd89-4a57-9ae2-95ae141940d9/GitRepos/sys-info-rs/target/x86_64-pc-windows-gnu/debug/build/sys-info-d0550d93732dd07b/out/c/linux.o" "-c" "c/linux.c" with args "x86_64-w64-mingw32-gcc" did not execute successfully (status code exit code: 1).

', /home/lion328/.cargo/registry/src/github.com-1ecc6299db9ec823/gcc-0.3.54/src/lib.rs:1670:4
note: Run with `RUST_BACKTRACE=1` for a backtrace.

As you can see its build c/linux.c instead of c/windows.c. This might be caused by build.rs from using cfg!(target_os = "...") to tell the target OS.

macos' get_os_release leaks and misbehaves

The get_os_release C function allocates the buffer on the heap and returns it, but on the rust side it doesn't take ownership of the memory:

buf = malloc(LEN);
let typ = ffi::CStr::from_ptr(rp).to_bytes();

Also, if an error occurs on the C side it uses strncpy to set it to "Unknown", but on rust's side it expects a NULL pointer to be returned in case of error:

// At this point `len` is _most likely_ set to `0` (e.g. in case of ENOMEM).
// We copy our string and reset the length.
strncpy(buf, "Unknown", LEN);
if rp == std::ptr::null() {
    Err(Error::Unknown)
}

There are other heap allocations on the C side I haven't verified are handled correctly on rust's side.

Fails on FreeBSD armv7,i386,powerpc architectures: error: conflicting types for 'get_cpu_speed'

Please see a complete log: http://beefy17.nyi.freebsd.org/data/main-i386-default/p560362_s58661b3ba9/logs/starship-0.48.0.log (IPv6 URL).

warning: c/freebsd.c:31:10: error: conflicting types for 'get_cpu_speed'
warning: uint64_t get_cpu_speed(void) {
warning:          ^
warning: c/info.h:31:15: note: previous declaration is here
warning: unsigned long get_cpu_speed(void);
warning:               ^
warning: c/freebsd.c:47:10: error: conflicting types for 'get_proc_total'
warning: uint64_t get_proc_total(void) {
warning:          ^
warning: c/info.h:34:15: note: previous declaration is here
warning: unsigned long get_proc_total(void);
warning:               ^
warning: 2 errors generated.

error: failed to run custom build command for `sys-info v0.7.0`

Caused by:
  process didn't exit successfully: `/wrkdirs/usr/ports/shells/starship/work/target/release/build/sys-info-1abc58d520aeca1b/build-script-build` (exit code: 1)
  --- stdout
  cargo:rustc-flags=-l pthread
  TARGET = Some("i686-unknown-freebsd")
  OPT_LEVEL = Some("3")
  HOST = Some("i686-unknown-freebsd")
  CC_i686-unknown-freebsd = None
  CC_i686_unknown_freebsd = None
  HOST_CC = None
  CC = Some("cc")
  CFLAGS_i686-unknown-freebsd = None
  CFLAGS_i686_unknown_freebsd = None
  HOST_CFLAGS = None
  CFLAGS = Some("-O2 -pipe  -fstack-protector-strong -fno-strict-aliasing ")
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("false")
  CARGO_CFG_TARGET_FEATURE = None
  running: "cc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m32" "-O2" "-pipe" "-fstack-protector-strong" "-fno-strict-aliasing" "-o" "/wrkdirs/usr/ports/shells/starship/work/target/release/build/sys-info-112f9ce0cf325461/out/c/freebsd.o" "-c" "c/freebsd.c"
  cargo:warning=c/freebsd.c:31:10: error: conflicting types for 'get_cpu_speed'
  cargo:warning=uint64_t get_cpu_speed(void) {
  cargo:warning=         ^
  cargo:warning=c/info.h:31:15: note: previous declaration is here
  cargo:warning=unsigned long get_cpu_speed(void);
  cargo:warning=              ^
  cargo:warning=c/freebsd.c:47:10: error: conflicting types for 'get_proc_total'
  cargo:warning=uint64_t get_proc_total(void) {
  cargo:warning=         ^
  cargo:warning=c/info.h:34:15: note: previous declaration is here
  cargo:warning=unsigned long get_proc_total(void);
  cargo:warning=              ^
  cargo:warning=2 errors generated.
  exit code: 1

  --- stderr


  error occurred: Command "cc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m32" "-O2" "-pipe" "-fstack-protector-strong" "-fno-strict-aliasing" "-o" "/wrkdirs/usr/ports/shells/starship/work/target/release/build/sys-info-112f9ce0cf325461/out/c/freebsd.o" "-c" "c/freebsd.c" with args "cc" did not execute successfully (status code exit code: 1).


warning: build failed, waiting for other jobs to finish...

Build fails on armv7: conflicting types for 'get_proc_total'

     Running `/wrkdirs/usr/ports/devel/gitui/work/target/release/build/backtrace-b6ff962af2568d6a/build-script-build`
The following warnings were emitted during compilation:

warning: c/freebsd.c:31:10: error: conflicting types for 'get_cpu_speed'
warning: uint64_t get_cpu_speed(void) {
warning:          ^
warning: c/info.h:31:15: note: previous declaration is here
warning: unsigned long get_cpu_speed(void);
warning:               ^
warning: c/freebsd.c:47:10: error: conflicting types for 'get_proc_total'
warning: uint64_t get_proc_total(void) {
warning:          ^
warning: c/info.h:34:15: note: previous declaration is here
warning: unsigned long get_proc_total(void);
warning:               ^
warning: 2 errors generated.

error: failed to run custom build command for `sys-info v0.9.1`

FreeBSD 13

cargo build fails on ppc64le

Hi,

I am working on porting sys-info-rs on ppc64le and running into the following issue while building it

Compiling sys-info v0.4.1 (file:///root/sys-info-rs)
error[E0308]: mismatched types
--> lib.rs:81:60
|
81 | Ok(String::from_utf8_lossy(ffi::CStr::from_ptr(get_os_type()).to_bytes()).into_owned())
| ^^^^^^^^^^^^^ expected u8, found i8
|
= note: expected type *const u8
found type *const i8
= help: here are some functions which might fulfill your needs:
- .offset(...)
- .wrapping_offset(...)

error[E0308]: mismatched types
--> lib.rs:100:60
|
100 | Ok(String::from_utf8_lossy(ffi::CStr::from_ptr(get_os_release()).to_bytes())
| ^^^^^^^^^^^^^^^^ expected u8, found i8
|
= note: expected type *const u8
found type *const i8
= help: here are some functions which might fulfill your needs:
- .offset(...)
- .wrapping_offset(...)

error: aborting due to 2 previous errors

error: Could not compile sys-info.

To learn more, run the command again with --verbose.

Looks like an issue due to the difference in signedness between Power and Intel.

Feature request: cache information

Would it be possible to add information on CPU cache sizes, as returned e.g. by the lscpu function on Linux or by GetLogicalProcessorInformation on Windows?

Thanks.

Version 0.51+ fails to compile with MUSL

When using musl as a target, I get the following error:

Compiling sys-info v0.5.2 (file:///home/rust/src/sys-info-rs)
error[E0432]: unresolved import `libc::sysctl`
  --> lib.rs:17:5
   |
17 | use libc::sysctl;
   |     ^^^^^^^^^^^^ no `sysctl` in the root. Did you mean to use `shmctl`?

error: aborting due to previous error(s)

error: Could not compile `sys-info`.

To learn more, run the command again with --verbose.

Version 0.50 works fine.

It appears that libc doesn't have a sysctl function for the musl target, but does for other targets.

Looking at the code, this is only used with mac osx in the boottime() function.

fn boottime - expected enum `Result`, found `()`

On latest Rust Nightly:

error[E0308]: mismatched types
   --> /Users/mike/.cargo/registry/src/github.com-1ecc6299db9ec823/sys-info-0.9.0/lib.rs:812:22
    |
812 | pub fn boottime() -> Result<timeval, Error> {
    |        --------      ^^^^^^^^^^^^^^^^^^^^^^ expected enum `Result`, found `()`
    |        |
    |        implicitly returns `()` as its body has no tail or `return` expression
    |
    = note:   expected enum `Result<timeval, Error>`
            found unit type `()`

➕ 1️⃣ for 💖GitHub Sponsors and Discussions!

Crates.io build fails on stable-x86_64-pc-windows-msvc

Full rustc version: stable-x86_64-pc-windows-msvc unchanged - rustc 1.19.0 (0ade33941 2017-07-17)

Build error:

   Compiling sys-info v0.5.1
error[E0432]: unresolved import `libc::sysctl`
  --> C:\Users\Layl\.cargo\registry\src\github.com-1ecc6299db9ec823\sys-info-0.5.1\lib.rs:16:5
   |
16 | use libc::sysctl;
   |     ^^^^^^^^^^^^ no `sysctl` in the root

error[E0412]: cannot find type `suseconds_t` in module `libc`
   --> C:\Users\Layl\.cargo\registry\src\github.com-1ecc6299db9ec823\sys-info-0.5.1\lib.rs:312:39
    |
312 |         bt.tv_usec = secs[1] as libc::suseconds_t;
    |                                       ^^^^^^^^^^^ not found in `libc`

error[E0308]: mismatched types
   --> C:\Users\Layl\.cargo\registry\src\github.com-1ecc6299db9ec823\sys-info-0.5.1\lib.rs:311:21
    |
311 |         bt.tv_sec = secs[0]  as libc::time_t;
    |                     ^^^^^^^^^^^^^^^^^^^^^^^^ expected i32, found i64

error: aborting due to previous error(s)

error: Could not compile `sys-info`.

To learn more, run the command again with --verbose.

0.7.0 fails to build for iOS target

 error[E0308]: mismatched types
    --> /Users/administrator/.cargo/registry/src/github.com-1ecc6299db9ec823/sys-info-0.7.0/lib.rs:618:22
     |
 618 | pub fn boottime() -> Result<timeval, Error> {
     |        --------      ^^^^^^^^^^^^^^^^^^^^^^ expected enum `std::result::Result`, found `()`
     |        |
     |        implicitly returns `()` as its body has no tail or `return` expression
     |
     = note:   expected enum `std::result::Result<libc::timeval, Error>`
             found unit type `()`
 error: aborting due to previous error
 For more information about this error, try `rustc --explain E0308`.
 error: could not compile `sys-info`.
 To learn more, run the command again with --verbose.
 warning: build failed, waiting for other jobs to finish...
 error: build failed
 make: *** [apple-ios-x86_64] Error 101

unsupported system: freebsd

error: failed to run custom build command for `sys-info v0.5.7`

Caused by:
  process didn't exit successfully: `/usr/home/yuri/rust-learn/tikv/target/debug/build/sys-info-dc048a4e20422394/build-script-build` (exit code: 101)
--- stderr
thread 'main' panicked at 'unsupported system: freebsd', /home/yuri/.cargo/registry/src/github.com-1ecc6299db9ec823/sys-info-0.5.7/build.rs:17:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

warning: build failed, waiting for other jobs to finish...

getting cpu speed sometimes (ppc64 / ppc64le) still fails

[ignatenkobrain@ppc64-test ~][PROD]$ lscpu
Architecture:        ppc64
CPU op-mode(s):      32-bit, 64-bit
Byte Order:          Big Endian
CPU(s):              2
On-line CPU(s) list: 0,1
Thread(s) per core:  1
Core(s) per socket:  1
Socket(s):           2
NUMA node(s):        1
Model:               2.1 (pvr 004b 0201)
Model name:          POWER8 (architected), altivec supported
Hypervisor vendor:   KVM
Virtualization type: para
L1d cache:           64K
L1i cache:           32K
NUMA node0 CPU(s):   0,1

there is no bogomips or mhz....

Meminfo fails on WSL

On a machine running WSL (I used Arch but it shouldn't matter):

While the build passes, trying to run the mem_info function fails at runtime because WSL doesn't report MemAvailable (which is like several old Linux kernels.)

[hoverbear@Obsidian sys-info-rs]$ cargo test
warning: c/linux.c: In function ‘get_loadavg’:
warning: c/linux.c:62:12: warning: ‘avg’ is used uninitialized in this function [-Wuninitialized]
warning:      return avg;
warning:             ^~~
warning: c/linux.c: In function ‘get_mem_info’:
warning: c/linux.c:76:12: warning: ‘info’ is used uninitialized in this function [-Wuninitialized]
warning:      return info;
warning:             ^~~~
    Finished dev [unoptimized + debuginfo] target(s) in 0.05s
     Running target/debug/deps/sys_info-0b3fbeb5431d68b8

running 10 tests
test test::test_cpu_num ... ok
test test::test_boottime ... ok
test test::test_cpu_speed ... ok
test test::test_disk_info ... ok
test test::test_loadavg ... ok
test test::test_os_release ... ok
test test::test_os_type ... ok
test test::test_proc_total ... ok
test test::test_mem_info ... FAILED
test test::test_hostname ... ok

failures:

---- test::test_mem_info stdout ----
thread 'test::test_mem_info' panicked at 'called `Result::unwrap()` on an `Err` value: Unknown', src/libcore/result.rs:997:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.


failures:
    test::test_mem_info

test result: FAILED. 9 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

error: test failed, to rerun pass '--lib'
[hoverbear@Obsidian sys-info-rs]$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

You can see the output from /proc/meminfo:

It's failing at:

avail: *meminfo_hashmap.get("MemAvailable").ok_or(Error::Unknown)?,

[hoverbear@Obsidian sys-info-rs]$ cat /proc/meminfo
MemTotal:       33462384 kB
MemFree:        22064676 kB
Buffers:           34032 kB
Cached:           188576 kB
SwapCached:            0 kB
Active:           167556 kB
Inactive:         157876 kB
Active(anon):     103104 kB
Inactive(anon):    17440 kB
Active(file):      64452 kB
Inactive(file):   140436 kB
Unevictable:           0 kB
Mlocked:               0 kB
SwapTotal:      60969468 kB
SwapFree:       60920476 kB
Dirty:                 0 kB
Writeback:             0 kB
AnonPages:        102824 kB
Mapped:            71404 kB
Shmem:             17720 kB
Slab:              13868 kB
SReclaimable:       6744 kB
SUnreclaim:         7124 kB
KernelStack:        2848 kB
PageTables:         2524 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:      515524 kB
Committed_AS:    3450064 kB
VmallocTotal:     122880 kB
VmallocUsed:       21296 kB
VmallocChunk:      66044 kB
HardwareCorrupted:     0 kB
AnonHugePages:      2048 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:       12280 kB
DirectMap4M:      897024 kB

You can see how this problem as fixed in another repo: polybar/polybar#405 which lead to polybar/polybar#410

sys-info v0.5.10 broken on windows

https://github.com/denoland/deno/pull/4270/checks?check_run_id=490557406

error[E0425]: cannot find function `sysconf` in crate `libc`
##[error]   --> C:\Users\runneradmin\.cargo\registry\src\github.com-1ecc6299db9ec823\sys-info-0.5.10\lib.rs:396:34
    |
396 |             let buf_size = libc::sysconf(libc::_SC_HOST_NAME_MAX) as usize;
    |                                  ^^^^^^^ not found in `libc`

error[E0425]: cannot find value `_SC_HOST_NAME_MAX` in crate `libc`
##[error]   --> C:\Users\runneradmin\.cargo\registry\src\github.com-1ecc6299db9ec823\sys-info-0.5.10\lib.rs:396:48
    |
396 |             let buf_size = libc::sysconf(libc::_SC_HOST_NAME_MAX) as usize;
    |                                                ^^^^^^^^^^^^^^^^^ not found in `libc`

error[E0425]: cannot find function `gethostname` in crate `libc`
##[error]   --> C:\Users\runneradmin\.cargo\registry\src\github.com-1ecc6299db9ec823\sys-info-0.5.10\lib.rs:398:22
    |
398 |             if libc::gethostname(buf.as_mut_ptr() as *mut libc::c_char, buf_size) < 0 {
    |                      ^^^^^^^^^^^ help: a function with a similar name exists: `getsockname`

It seems v0.5.9 was also broken #42

sys-info can't be installed on termux

Describe the bug
try cargo install sys-info

To Reproduce
I tried running cargo install bat, since sys-info is a dependency.

error: failed to run custom build command for `sys-info v0.9.1`

Caused by:
  process didn't exit successfully: `/data/data/com.termux/files/usr/tmp/cargo-installKZRXcQ/release/build/sys-info-26f569e1e06f06ef/build-script-build` (exit status: 1)
  --- stdout
  TARGET = Some("aarch64-linux-android")
  OPT_LEVEL = Some("3")
  HOST = Some("aarch64-linux-android")
  cargo:rerun-if-env-changed=CC_aarch64-linux-android
  CC_aarch64-linux-android = None
  cargo:rerun-if-env-changed=CC_aarch64_linux_android
  CC_aarch64_linux_android = None
  cargo:rerun-if-env-changed=HOST_CC
  HOST_CC = None
  cargo:rerun-if-env-changed=CC
  CC = None
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("false")
  CARGO_CFG_TARGET_FEATURE = Some("neon")
  cargo:rerun-if-env-changed=CFLAGS_aarch64-linux-android
  CFLAGS_aarch64-linux-android = None
  cargo:rerun-if-env-changed=CFLAGS_aarch64_linux_android
  CFLAGS_aarch64_linux_android = None
  cargo:rerun-if-env-changed=HOST_CFLAGS
  HOST_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  running: "aarch64-linux-android-gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-Wall" "-Wextra" "-o" "/data/data/com.termux/files/usr/tmp/cargo-installKZRXcQ/release/build/sys-info-51d975ed4f6238fe/out/c/linux.o" "-c" "c/linux.c"
  cargo:warning=c/linux.c:96:11: error: call to undeclared library function 'index' with type 'char *(const char *, int)'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]

  cargo:warning=   96 |                 mount = index(procline, ' ');

  cargo:warning=      |                         ^

  cargo:warning=c/linux.c:96:11: note: include the header <strings.h> or explicitly provide a declaration for 'index'

  cargo:warning=1 error generated.

  exit status: 1

  --- stderr


  error occurred: Command "aarch64-linux-android-gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-Wall" "-Wextra" "-o" "/data/data/com.termux/files/usr/tmp/cargo-installKZRXcQ/release/build/sys-info-51d975ed4f6238fe/out/c/linux.o" "-c" "c/linux.c" with args "aarch64-linux-android-gcc" did not execute successfully (status code exit status: 1).


warning: build failed, waiting for other jobs to finish...
error: failed to compile `bat v0.24.0`, intermediate artifacts can be found at `/data/data/com.termux/files/usr/tmp/cargo-installKZRXcQ`.
To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.

可以支持获取本机网络信息吗?

就像node这样?

os.networkInterfaces()
{ lo: 
  [ { address: '127.0.0.1',
      netmask: '255.0.0.0',
      family: 'IPv4',
      mac: '00:00:00:00:00:00',
      internal: true },
    { address: '::1',
      netmask: 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
      family: 'IPv6',
      mac: '00:00:00:00:00:00',
      scopeid: 0,
      internal: true } ],
 wlan0: 
  [ { address: '192.168.1.2',
      netmask: '255.255.255.0',
      family: 'IPv4',
      mac: '00:xx:0x:xx:xx:xx',
      internal: false },
    { address: 'fe80::25:ff:fec0:28',
      netmask: 'ffff:ffff:ffff:ffff::',
      family: 'IPv6',
      mac: '00:xx:0x:xx:xx:xx',
      scopeid: 3,
      internal: false } ] }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.