Skip to content

Commit 54fc5c4

Browse files
committed
Auto merge of #289 - fnichol:fix-musl-ioctl-constants, r=alexcrichton
Fix ioctl constants for musl target envs. Heya! I ran across this issue today while trying to build a portable static binary using the `x86_64-unknown-linux-musl` target. Took a bit of digging to make sure I understood what was going on, and while I may still be off the mark, I believe this is a fix to my issue. Thanks!! ---- According to musl's source, the `ioctl` [function signature][musl-ioctl-h] takes an `int` as the request argument (i.e. an `i32`) which is reflected in this crate's [ioctl binding][musl-ioctl-rs]. It looks like when the ioctl constants were added that [glibc's default][glibc-ioctl-h] of a `c_ulong` type was used for the musl values as well, rather than a `c_int` type. This change updates these constants to a `c_int` so that they match the expected function call type. Here is a minimal reproduction of the issue. Given this Rust program: ```rust extern crate libc; use libc::{ioctl, winsize, STDOUT_FILENO, TIOCGWINSZ}; fn main() { let mut wsize = winsize { ws_row: 0, ws_col: 0, ws_xpixel: 0, ws_ypixel: 0, }; unsafe { ioctl(STDOUT_FILENO, TIOCGWINSZ, &mut wsize); } println!("Sizes: {{ rows: {}, cols: {}, xpixel: {}, ypixel: {} }}", wsize.ws_row, wsize.ws_col, wsize.ws_xpixel, wsize.ws_ypixel); } ``` When run against the `x86_64-unknwon-linux-gnu` and `x86_64-unknown-linux-musl` targets, we see the difference in behavior: ``` > cargo clean > cargo run --target=x86_64-unknown-linux-gnu Compiling libc v0.2.11 Compiling libc-musl-ioctl v0.1.0 (file:///src/libc-musl-ioctl) Running `target/x86_64-unknown-linux-gnu/debug/libc-musl-ioctl` Sizes: { rows: 28, cols: 211, xpixel: 0, ypixel: 0 } > cargo clean > cargo run --target=x86_64-unknown-linux-musl Compiling libc v0.2.11 Compiling libc-musl-ioctl v0.1.0 (file:///src/libc-musl-ioctl) src/main.rs:13:30: 13:40 error: mismatched types: expected `i32`, found `u64` [E0308] src/main.rs:13 ioctl(STDOUT_FILENO, TIOCGWINSZ, &mut wsize); ^~~~~~~~~~ src/main.rs:13:30: 13:40 help: run `rustc --explain E0308` to see a detailed explanation error: aborting due to previous error Could not compile `libc-musl-ioctl`. To learn more, run the command again with --verbose. ``` Working against this fix: ``` > cargo clean > cargo run --target=x86_64-unknown-linux-gnu Updating git repository `https://github.com/fnichol/rust-lang-libc.git` Compiling libc v0.2.11 (https://github.com/fnichol/rust-lang-libc.git?branch=fix-musl-ioctl-constants#3285f387) Compiling libc-musl-ioctl v0.1.0 (file:///src/libc-musl-ioctl) Running `target/x86_64-unknown-linux-gnu/debug/libc-musl-ioctl` Sizes: { rows: 28, cols: 211, xpixel: 0, ypixel: 0 } > cargo clean > cargo run --target=x86_64-unknown-linux-musl Compiling libc v0.2.11 (https://github.com/fnichol/rust-lang-libc.git?branch=fix-musl-ioctl-constants#3285f387) Compiling libc-musl-ioctl v0.1.0 (file:///src/libc-musl-ioctl) Running `target/x86_64-unknown-linux-musl/debug/libc-musl-ioctl` Sizes: { rows: 28, cols: 211, xpixel: 0, ypixel: 0 } ``` [musl-ioctl-rs]: https://doc.rust-lang.org/libc/x86_64-unknown-linux-musl/libc/fn.ioctl.html [musl-ioctl-h]: https://git.musl-libc.org/cgit/musl/tree/include/sys/ioctl.h [glibc-ioctl-h]: http://bazaar.launchpad.net/~vcs-imports/glibc/master/view/head:/include/sys/ioctl.h
2 parents b19b546 + 78d9be2 commit 54fc5c4

File tree

3 files changed

+61
-61
lines changed

3 files changed

+61
-61
lines changed

src/unix/notbsd/linux/musl/b32/x86.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -286,36 +286,36 @@ pub const IEXTEN: ::tcflag_t = 0x00008000;
286286
pub const TOSTOP: ::tcflag_t = 0x00000100;
287287
pub const FLUSHO: ::tcflag_t = 0x00001000;
288288

289-
pub const TCGETS: ::c_ulong = 0x5401;
290-
pub const TCSETS: ::c_ulong = 0x5402;
291-
pub const TCSETSW: ::c_ulong = 0x5403;
292-
pub const TCSETSF: ::c_ulong = 0x5404;
293-
pub const TCGETA: ::c_ulong = 0x5405;
294-
pub const TCSETA: ::c_ulong = 0x5406;
295-
pub const TCSETAW: ::c_ulong = 0x5407;
296-
pub const TCSETAF: ::c_ulong = 0x5408;
297-
pub const TCSBRK: ::c_ulong = 0x5409;
298-
pub const TCXONC: ::c_ulong = 0x540A;
299-
pub const TCFLSH: ::c_ulong = 0x540B;
300-
pub const TIOCGSOFTCAR: ::c_ulong = 0x5419;
301-
pub const TIOCSSOFTCAR: ::c_ulong = 0x541A;
302-
pub const TIOCLINUX: ::c_ulong = 0x541C;
303-
pub const TIOCGSERIAL: ::c_ulong = 0x541E;
304-
pub const TIOCEXCL: ::c_ulong = 0x540C;
305-
pub const TIOCNXCL: ::c_ulong = 0x540D;
306-
pub const TIOCSCTTY: ::c_ulong = 0x540E;
307-
pub const TIOCGPGRP: ::c_ulong = 0x540F;
308-
pub const TIOCSPGRP: ::c_ulong = 0x5410;
309-
pub const TIOCOUTQ: ::c_ulong = 0x5411;
310-
pub const TIOCSTI: ::c_ulong = 0x5412;
311-
pub const TIOCGWINSZ: ::c_ulong = 0x5413;
312-
pub const TIOCSWINSZ: ::c_ulong = 0x5414;
313-
pub const TIOCMGET: ::c_ulong = 0x5415;
314-
pub const TIOCMBIS: ::c_ulong = 0x5416;
315-
pub const TIOCMBIC: ::c_ulong = 0x5417;
316-
pub const TIOCMSET: ::c_ulong = 0x5418;
317-
pub const FIONREAD: ::c_ulong = 0x541B;
318-
pub const TIOCCONS: ::c_ulong = 0x541D;
289+
pub const TCGETS: ::c_int = 0x5401;
290+
pub const TCSETS: ::c_int = 0x5402;
291+
pub const TCSETSW: ::c_int = 0x5403;
292+
pub const TCSETSF: ::c_int = 0x5404;
293+
pub const TCGETA: ::c_int = 0x5405;
294+
pub const TCSETA: ::c_int = 0x5406;
295+
pub const TCSETAW: ::c_int = 0x5407;
296+
pub const TCSETAF: ::c_int = 0x5408;
297+
pub const TCSBRK: ::c_int = 0x5409;
298+
pub const TCXONC: ::c_int = 0x540A;
299+
pub const TCFLSH: ::c_int = 0x540B;
300+
pub const TIOCGSOFTCAR: ::c_int = 0x5419;
301+
pub const TIOCSSOFTCAR: ::c_int = 0x541A;
302+
pub const TIOCLINUX: ::c_int = 0x541C;
303+
pub const TIOCGSERIAL: ::c_int = 0x541E;
304+
pub const TIOCEXCL: ::c_int = 0x540C;
305+
pub const TIOCNXCL: ::c_int = 0x540D;
306+
pub const TIOCSCTTY: ::c_int = 0x540E;
307+
pub const TIOCGPGRP: ::c_int = 0x540F;
308+
pub const TIOCSPGRP: ::c_int = 0x5410;
309+
pub const TIOCOUTQ: ::c_int = 0x5411;
310+
pub const TIOCSTI: ::c_int = 0x5412;
311+
pub const TIOCGWINSZ: ::c_int = 0x5413;
312+
pub const TIOCSWINSZ: ::c_int = 0x5414;
313+
pub const TIOCMGET: ::c_int = 0x5415;
314+
pub const TIOCMBIS: ::c_int = 0x5416;
315+
pub const TIOCMBIC: ::c_int = 0x5417;
316+
pub const TIOCMSET: ::c_int = 0x5418;
317+
pub const FIONREAD: ::c_int = 0x541B;
318+
pub const TIOCCONS: ::c_int = 0x541D;
319319

320320
pub const SYS_gettid: ::c_long = 224;
321321
pub const SYS_perf_event_open: ::c_long = 336;

src/unix/notbsd/linux/musl/b64/mod.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -294,36 +294,36 @@ pub const IEXTEN: ::tcflag_t = 0x00008000;
294294
pub const TOSTOP: ::tcflag_t = 0x00000100;
295295
pub const FLUSHO: ::tcflag_t = 0x00001000;
296296

297-
pub const TCGETS: ::c_ulong = 0x5401;
298-
pub const TCSETS: ::c_ulong = 0x5402;
299-
pub const TCSETSW: ::c_ulong = 0x5403;
300-
pub const TCSETSF: ::c_ulong = 0x5404;
301-
pub const TCGETA: ::c_ulong = 0x5405;
302-
pub const TCSETA: ::c_ulong = 0x5406;
303-
pub const TCSETAW: ::c_ulong = 0x5407;
304-
pub const TCSETAF: ::c_ulong = 0x5408;
305-
pub const TCSBRK: ::c_ulong = 0x5409;
306-
pub const TCXONC: ::c_ulong = 0x540A;
307-
pub const TCFLSH: ::c_ulong = 0x540B;
308-
pub const TIOCGSOFTCAR: ::c_ulong = 0x5419;
309-
pub const TIOCSSOFTCAR: ::c_ulong = 0x541A;
310-
pub const TIOCLINUX: ::c_ulong = 0x541C;
311-
pub const TIOCGSERIAL: ::c_ulong = 0x541E;
312-
pub const TIOCEXCL: ::c_ulong = 0x540C;
313-
pub const TIOCNXCL: ::c_ulong = 0x540D;
314-
pub const TIOCSCTTY: ::c_ulong = 0x540E;
315-
pub const TIOCGPGRP: ::c_ulong = 0x540F;
316-
pub const TIOCSPGRP: ::c_ulong = 0x5410;
317-
pub const TIOCOUTQ: ::c_ulong = 0x5411;
318-
pub const TIOCSTI: ::c_ulong = 0x5412;
319-
pub const TIOCGWINSZ: ::c_ulong = 0x5413;
320-
pub const TIOCSWINSZ: ::c_ulong = 0x5414;
321-
pub const TIOCMGET: ::c_ulong = 0x5415;
322-
pub const TIOCMBIS: ::c_ulong = 0x5416;
323-
pub const TIOCMBIC: ::c_ulong = 0x5417;
324-
pub const TIOCMSET: ::c_ulong = 0x5418;
325-
pub const FIONREAD: ::c_ulong = 0x541B;
326-
pub const TIOCCONS: ::c_ulong = 0x541D;
297+
pub const TCGETS: ::c_int = 0x5401;
298+
pub const TCSETS: ::c_int = 0x5402;
299+
pub const TCSETSW: ::c_int = 0x5403;
300+
pub const TCSETSF: ::c_int = 0x5404;
301+
pub const TCGETA: ::c_int = 0x5405;
302+
pub const TCSETA: ::c_int = 0x5406;
303+
pub const TCSETAW: ::c_int = 0x5407;
304+
pub const TCSETAF: ::c_int = 0x5408;
305+
pub const TCSBRK: ::c_int = 0x5409;
306+
pub const TCXONC: ::c_int = 0x540A;
307+
pub const TCFLSH: ::c_int = 0x540B;
308+
pub const TIOCGSOFTCAR: ::c_int = 0x5419;
309+
pub const TIOCSSOFTCAR: ::c_int = 0x541A;
310+
pub const TIOCLINUX: ::c_int = 0x541C;
311+
pub const TIOCGSERIAL: ::c_int = 0x541E;
312+
pub const TIOCEXCL: ::c_int = 0x540C;
313+
pub const TIOCNXCL: ::c_int = 0x540D;
314+
pub const TIOCSCTTY: ::c_int = 0x540E;
315+
pub const TIOCGPGRP: ::c_int = 0x540F;
316+
pub const TIOCSPGRP: ::c_int = 0x5410;
317+
pub const TIOCOUTQ: ::c_int = 0x5411;
318+
pub const TIOCSTI: ::c_int = 0x5412;
319+
pub const TIOCGWINSZ: ::c_int = 0x5413;
320+
pub const TIOCSWINSZ: ::c_int = 0x5414;
321+
pub const TIOCMGET: ::c_int = 0x5415;
322+
pub const TIOCMBIS: ::c_int = 0x5416;
323+
pub const TIOCMBIC: ::c_int = 0x5417;
324+
pub const TIOCMSET: ::c_int = 0x5418;
325+
pub const FIONREAD: ::c_int = 0x541B;
326+
pub const TIOCCONS: ::c_int = 0x541D;
327327

328328
cfg_if! {
329329
if #[cfg(target_arch = "aarch64")] {

src/unix/notbsd/linux/musl/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ pub const TCSANOW: ::c_int = 0;
143143
pub const TCSADRAIN: ::c_int = 1;
144144
pub const TCSAFLUSH: ::c_int = 2;
145145

146-
pub const TIOCINQ: ::c_ulong = ::FIONREAD;
146+
pub const TIOCINQ: ::c_int = ::FIONREAD;
147147

148148
pub const RTLD_GLOBAL: ::c_int = 0x100;
149149
pub const RTLD_NOLOAD: ::c_int = 0x4;

0 commit comments

Comments
 (0)