Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about list of longs #26

Open
rudolphfroger opened this issue Feb 25, 2020 · 3 comments
Open

Question about list of longs #26

rudolphfroger opened this issue Feb 25, 2020 · 3 comments

Comments

@rudolphfroger
Copy link

Hi,

First of all, thanks for this library. I'm very new to Rust so this might be a stupid question. I'm trying to read the "kern.cp_time" and "kern.cp_times" Ctl's on FreeBSD. This should be a list of long integers (user, nice, sys, intr, idle). sysctl-rs says it's a Long type value and the value I get is just one i64 value but sysctl kern.cp_time gives me the list of all 5 numbers. Could you point me the way on how to read all 5?

Thanks, Rudolph

@johalun
Copy link
Owner

johalun commented Feb 25, 2020

Hi
That's a good question! I haven't actually tried to read this myself and this crate does not have built-in support for the array type (yet). No sure this would work but you could try value_as() which is described in the example here https://github.com/johalun/sysctl-rs/blob/master/examples/value_as.rs and with the struct

#[repr(C)]
struct Times {
    times: [libc::c_long;5],
}

@rudolphfroger
Copy link
Author

rudolphfroger commented Feb 26, 2020

Thanks, I've already tried that but it seems only the first long is read by sysctl-rs, probably because its type is LU. See line 250 of src/unix/funcs.rs. Before this line we probably have the complete array in val (didn't test) but then we read this into a 64 bit integer and loose the remaining bytes.

I do not feel confident yet to write a patch, I'm currently writing my first lines of rust...

@rudolphfroger
Copy link
Author

I looked into the code of the sysctl utility and it seems to assume that all numeric types are potentialy arrays: https://github.com/freebsd/freebsd/blob/master/sbin/sysctl/sysctl.c#L1075-L1134 . Maybe sysctl-rs could do something similar.

jyoung15 added a commit to jyoung15/sysctl-rs that referenced this issue Apr 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants