From 5a81fc6541b8aabbc7caf1afb2cc82b522e9854a Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Fri, 2 Dec 2022 21:21:09 -0500 Subject: [PATCH] Update use of libc::timespec to prepare for future libc version In a future release of the `libc` crate, `libc::timespec` will contain private padding fields on `*-linux-musl` targets and so the struct will no longer be able to be created using the literal initialization syntax. Update `TS_ZERO` to create a value by initializing an array of the correct size to `0` and then transmuting to `libc::timespec`. Update struct literal use of `libc::timespec` to initialize to `TS_ZERO` and then manually update the appropriate fields. Also updates a raw syscall to use the libc function instead as on musl 1.2, it correctly handles `libc::timespec` values which, in musl 1.2, are always 16 bytes in length regardless of platform. --- src/epoll.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/epoll.rs b/src/epoll.rs index 59b7fc3..bf94b01 100644 --- a/src/epoll.rs +++ b/src/epoll.rs @@ -116,15 +116,16 @@ impl Poller { it_interval: TS_ZERO, it_value: match timeout { None => TS_ZERO, - Some(t) => libc::timespec { - tv_sec: t.as_secs() as libc::time_t, - tv_nsec: (t.subsec_nanos() as libc::c_long).into(), - }, + Some(t) => { + let mut ts = TS_ZERO; + ts.tv_sec = t.as_secs() as libc::time_t; + ts.tv_nsec = (t.subsec_nanos() as libc::c_long).into(); + ts + } }, }; - syscall!(syscall( - libc::SYS_timerfd_settime, + syscall!(timerfd_settime( timer_fd as libc::c_int, 0 as libc::c_int, &new_val as *const libc::itimerspec, @@ -262,10 +263,8 @@ impl Drop for Poller { } /// `timespec` value that equals zero. -const TS_ZERO: libc::timespec = libc::timespec { - tv_sec: 0, - tv_nsec: 0, -}; +const TS_ZERO: libc::timespec = + unsafe { std::mem::transmute([0u8; std::mem::size_of::()]) }; /// Epoll flags for all possible readability events. fn read_flags() -> libc::c_int {