facebookincubator / below

A time traveling resource monitor for modern Linux systems
Apache License 2.0
1.08k stars 61 forks source link

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

Open jirutka opened 7 months ago

jirutka commented 7 months ago
   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) };
    |                                                                                ++++++++++++++++++++
brianc118 commented 7 months ago

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

jirutka commented 7 months ago

No, this is from x86_64.

brianc118 commented 7 months ago

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 commented 7 months ago

termux/termux-packages#19609

pPanda-beta commented 3 months ago

This problem is there for libfs as well. cargo install --target x86_64-unknown-linux-musl xcp fails too.

error[E0308]: mismatched types
   --> /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/libfs-0.7.2/src/linux.rs:153:45
    |
153 |     if unsafe { libc::ioctl(fd.as_raw_fd(), FS_IOC_FIEMAP as u64, req_ptr) } != 0 {
    |                 -----------                 ^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `u64`
    |                 |
    |                 arguments to this function are incorrect
    |