From 9245e0727b422b3490ec401e4601d3cf1c443ccc Mon Sep 17 00:00:00 2001
From: Alan Somers <asomers@gmail.com>
Date: Sun, 13 Nov 2016 13:52:34 -0700
Subject: [PATCH] Fix various CI errors in PR #449

---
 libc-test/build.rs                        | 17 +++++++++++++++--
 src/unix/bsd/apple/mod.rs                 |  2 +-
 src/unix/bsd/freebsdlike/dragonfly/mod.rs |  2 +-
 src/unix/bsd/freebsdlike/freebsd/mod.rs   |  2 +-
 src/unix/bsd/netbsdlike/netbsd/mod.rs     |  2 +-
 src/unix/mod.rs                           |  5 +++++
 src/unix/notbsd/mod.rs                    |  8 ++++----
 7 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/libc-test/build.rs b/libc-test/build.rs
index 29f9d362..d2c98ae3 100644
--- a/libc-test/build.rs
+++ b/libc-test/build.rs
@@ -298,6 +298,9 @@ fn main() {
             // The alignment of this is 4 on 64-bit OSX...
             "kevent" if apple && x86_64 => true,
 
+            // This is actually a union, not a struct
+            "sigval" => true,
+
             _ => false
         }
     });
@@ -427,6 +430,10 @@ fn main() {
             // the symbol.
             "uname" if freebsd => true,
 
+            // lio_listio confuses the checker, probably because one of its
+            // arguments is an array
+            "lio_listio" if freebsd => true,
+
             _ => false,
         }
     });
@@ -446,7 +453,11 @@ fn main() {
         // sighandler_t type is super weird
         (struct_ == "sigaction" && field == "sa_sigaction") ||
         // __timeval type is a patch which doesn't exist in glibc
-        (linux && struct_ == "utmpx" && field == "ut_tv")
+        (linux && struct_ == "utmpx" && field == "ut_tv") ||
+        // sigval is actually a union, but we pretend it's a struct
+        (struct_ == "sigevent" && field == "sigev_value") ||
+        // aio_buf is "volatile void*" and Rust doesn't understand volatile
+        (struct_ == "aiocb" && field == "aio_buf")
     });
 
     cfg.skip_field(move |struct_, field| {
@@ -456,7 +467,9 @@ fn main() {
         // musl names this __dummy1 but it's still there
         (musl && struct_ == "glob_t" && field == "gl_flags") ||
         // musl seems to define this as an *anonymous* bitfield
-        (musl && struct_ == "statvfs" && field == "__f_unused")
+        (musl && struct_ == "statvfs" && field == "__f_unused") ||
+        // sigev_notify_thread_id is actually part of a sigev_un union
+        (struct_ == "sigevent" && field == "sigev_notify_thread_id")
     });
 
     cfg.fn_cname(move |name, cname| {
diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs
index a88c8b54..055fbd71 100644
--- a/src/unix/bsd/apple/mod.rs
+++ b/src/unix/bsd/apple/mod.rs
@@ -317,7 +317,7 @@ s! {
     pub struct sigevent {
         pub sigev_notify: ::c_int,
         pub sigev_signo: ::c_int,
-        pub sigev_value: ::intptr_t,    //actually a union of int and void*
+        pub sigev_value: ::sigval,
         __unused1: *mut ::c_void,       //actually a function pointer
         pub sigev_notify_attributes: *mut ::pthread_attr_t
     }
diff --git a/src/unix/bsd/freebsdlike/dragonfly/mod.rs b/src/unix/bsd/freebsdlike/dragonfly/mod.rs
index fbfb1c48..3a91bca0 100644
--- a/src/unix/bsd/freebsdlike/dragonfly/mod.rs
+++ b/src/unix/bsd/freebsdlike/dragonfly/mod.rs
@@ -50,7 +50,7 @@ s! {
         pub sigev_signo: ::c_int,       //actually a union
         #[cfg(target_pointer_width = "64")]
         __unused1: ::c_int,
-        pub sigev_value: ::intptr_t,    //actually a union of int and void*
+        pub sigev_value: ::sigval,
         __unused2: *mut ::c_void        //actually a function pointer
     }
 
diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs
index 706aea65..173f8383 100644
--- a/src/unix/bsd/freebsdlike/freebsd/mod.rs
+++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs
@@ -37,7 +37,7 @@ s! {
     pub struct sigevent {
         pub sigev_notify: ::c_int,
         pub sigev_signo: ::c_int,
-        pub sigev_value: ::intptr_t,    //actually a union of int and void*
+        pub sigev_value: ::sigval,
         //The rest of the structure is actually a union.  We expose only
         //sigev_notify_thread_id because it's the most useful union member.
         pub sigev_notify_thread_id: ::lwpid_t,
diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs
index 82f938e0..cb82f813 100644
--- a/src/unix/bsd/netbsdlike/netbsd/mod.rs
+++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs
@@ -46,7 +46,7 @@ s! {
     pub struct sigevent {
         pub sigev_notify: ::c_int,
         pub sigev_signo: ::c_int,
-        pub sigev_value: ::intptr_t,    //actually a union of int and void*
+        pub sigev_value: ::sigval,
         __unused1: *mut ::c_void,       //actually a function pointer
         pub sigev_notify_attributes: *mut ::c_void
     }
diff --git a/src/unix/mod.rs b/src/unix/mod.rs
index b79bb9f8..cf3a87ab 100644
--- a/src/unix/mod.rs
+++ b/src/unix/mod.rs
@@ -119,6 +119,11 @@ s! {
         pub l_onoff: ::c_int,
         pub l_linger: ::c_int,
     }
+
+    pub struct sigval {
+        // Actually a union of an int and a void*
+        pub sival_ptr: *mut ::c_void
+    }
 }
 
 pub const SIG_DFL: sighandler_t = 0 as sighandler_t;
diff --git a/src/unix/notbsd/mod.rs b/src/unix/notbsd/mod.rs
index 4d1ed886..92080f68 100644
--- a/src/unix/notbsd/mod.rs
+++ b/src/unix/notbsd/mod.rs
@@ -165,12 +165,12 @@ s! {
     }
 
     pub struct sigevent {
-        pub sigev_value: ::intptr_t,    //actually a union of int and void*
+        pub sigev_value: ::sigval,
         pub sigev_signo: ::c_int,
         pub sigev_notify: ::c_int,
-        // Actually a union.  We only expose _tid because it's the most useful
-        // member
-        pub _tid: ::c_int,
+        // Actually a union.  We only expose sigev_notify_thread_id because it's
+        // the most useful member
+        pub sigev_notify_thread_id: ::c_int,
         #[cfg(target_pointer_width = "64")]
         __unused1: [::c_int; 11],
         #[cfg(target_pointer_width = "32")]
-- 
GitLab