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

Linux 3.10.0-693.2.2.el7.x86_64 seems to somehow expose inconsistent sysctl API #1311

Closed
przygienda opened this issue Apr 2, 2019 · 9 comments

Comments

@przygienda
Copy link

ewnough said, API changed in mutability on first parameter and ptr/size? and that breaks crates like e.g. sysctl ...

@gnzlbg
Copy link
Contributor

gnzlbg commented Apr 2, 2019

ewnough said,

libc has a million APIs, so it would at least be nice to know which API, which target triple, minimum working example (no dependencies) with instructions to reproduce, etc.

@przygienda
Copy link
Author

nightly-x86_64-unknown-linux-gnu

sysctl(...) call changed mutability of parameters ...

reproduce: try to compile sysctl crate which takes libc and uses sysctl(..) calls

@gnzlbg
Copy link
Contributor

gnzlbg commented Apr 2, 2019

@gnzlbg
Copy link
Contributor

gnzlbg commented Apr 2, 2019

The last commit that changed sysctl on x86_64-unknown-linux-gnu is from 2 years ago (343b7c1) and landed on libc 0.2.33. There aren't any commits between 0.2.50 and 0.2.51 touching that API.

@gnzlbg
Copy link
Contributor

gnzlbg commented Apr 2, 2019

rust-semverver also reports no breaking changes between 0.2.50 and 0.2.51 on x86_64-unknown-linux-gnu (https://travis-ci.com/rust-lang/libc/jobs/188592924#L808, https://travis-ci.com/rust-lang/libc/jobs/188694789#L819) and it checks for changes in function signature types.

@przygienda
Copy link
Author

thanks, yet somehow it looks like updating to .51 broke sysctl here. I will try to get you an example today to verify it's not something else

@przygienda
Copy link
Author

Looked @ it further, it looks like an issues taht has nothing to do with newest libc release but been there since a bit. confusing, it compiles on other plaforms (BSD & MacOS)

Affects stable and nightly ...

--- here's the info, code taken out directly from sysctl-rs crate

extern crate libc;
use libc::{sysctl, c_int, c_void};

fn main() {
let oid: [c_int; 2] = [0, 3];

let mut len: usize = 32;

// We get results in this vector
let mut res: Vec<c_int> = vec![0; 32 as usize];

let name = "abc";

let ret = unsafe {
    sysctl(
        oid.as_ptr(),
        2,
        res.as_mut_ptr() as *mut c_void,
        &mut len,
        name.as_ptr() as *const c_void,
        name.len(),
    )
};

}
[prz@rahi-01 ~/gitlab/sysctl-break]$cargo +stable build
Compiling sysctl-break v0.1.0 (/home/prz/gitlab/sysctl-break)
error[E0308]: mismatched types
--> src/main.rs:16:13
|
16 | oid.as_ptr(),
| ^^^^^^^^^^^^ types differ in mutability
|
= note: expected type *mut i32
found type *const i32

error[E0308]: mismatched types
--> src/main.rs:20:13
|
20 | name.as_ptr() as *const c_void,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ in mutability
|
= note: expected type *mut libc::c_void
found type *const libc::c_void

error: aborting due to 2 previous errors

For more information about this error, try rustc --explain E0308.
error: Could not compile sysctl-break.

To learn more, run the command again with --verbose.
$cargo +stable --version
cargo 1.33.0 (f099fe94b 2019-02-12)
$uname -a
Linux 3.10.0-693.2.2.el7.x86_64 #1 SMP Tue Sep 12 22:26:13 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

@przygienda przygienda changed the title 0.2.51 broke sysctl API Linux 3.10.0-693.2.2.el7.x86_64 seems to somehow expose inconsistent sysctl API Apr 2, 2019
@gnzlbg
Copy link
Contributor

gnzlbg commented Apr 2, 2019

Is there a version of libc that compiled that example for that target correctly?

@przygienda
Copy link
Author

johalun/sysctl-rs#22 seems like crate was never tested on linux albeit I remember ages ago to have it working

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