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

Fails to build with musl due to incorrect arguments to libc::ioctl #8229

Open
jirutka opened this issue Apr 7, 2024 · 4 comments
Open

Fails to build with musl due to incorrect arguments to libc::ioctl #8229

jirutka opened this issue Apr 7, 2024 · 4 comments

Comments

@jirutka
Copy link
Contributor

jirutka commented Apr 7, 2024

   Compiling below-ethtool v0.8.1 (below-0.8.1/below/ethtool)
error[E0308]: mismatched types
   --> below/ethtool/src/reader.rs:36:58
    |
36  |     let exit_code = unsafe { libc::ioctl(fd.as_raw_fd(), nix::libc::SIOCETHTOOL, &ifr) };
    |                              -----------                 ^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u64`
    |                              |
    |                              arguments to this function are incorrect
    |
note: function defined here
   --> .cargo/registry/src/index.crates.io-6f17d22bba15001f/libc-0.2.153/src/unix/linux_like/linux/musl/mod.rs:850:12
    |
850 |     pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int;
    |            ^^^^^
help: you can convert a `u64` to an `i32` and panic if the converted value doesn't fit
    |
36  |     let exit_code = unsafe { libc::ioctl(fd.as_raw_fd(), nix::libc::SIOCETHTOOL.try_into().unwrap(), &ifr) };
    |                                                                                ++++++++++++++++++++
  • Alpine Linux Edge x86_64
  • musl libc 1.2.5
  • rust 1.77.0
@brianc118
Copy link
Contributor

Just confirming, are you building on a 32 bit system?

@jirutka
Copy link
Contributor Author

jirutka commented Apr 8, 2024

No, this is from x86_64.

@brianc118
Copy link
Contributor

Ah I see for musl the libc crate uses i32 instead of u64 for ioctl: https://docs.rs/libc/0.2.153/x86_64-unknown-linux-musl/libc/fn.ioctl.html

The constant is u64 in musl libc: https://docs.rs/libc/0.2.153/x86_64-unknown-linux-musl/libc/constant.SIOCETHTOOL.html.

Probably the best option here is to do the cast as suggested by the compiler. Do you mind testing out that change?

@tqfx
Copy link

tqfx commented Apr 25, 2024

termux/termux-packages#19609

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

3 participants