From 04e7551ea6c4dd19ed0c269876633eee4b68bea8 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Fri, 1 Mar 2019 08:22:37 -0700 Subject: [PATCH 1/4] Fix the build on OSX with libc 0.2.49 Several symbols are now marked as deprecated on OSX. Fix the build by marking these symbols' Nix wrappers as deprecated, too. --- CHANGELOG.md | 3 +++ src/sys/event.rs | 5 +++++ src/unistd.rs | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec74eb270d..35e32a4427 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,9 @@ This project adheres to [Semantic Versioning](http://semver.org/). ([#1020](https://github.com/nix-rust/nix/pull/1020)) ### Removed +- `Daemon`, `NOTE_REAP`, and `NOTE_EXIT_REPARENTED` are now deprecated on OSX + and iOS. + ([#1033](https://github.com/nix-rust/nix/pull/1033)) ## [0.13.0] - 2019-01-15 ### Added diff --git a/src/sys/event.rs b/src/sys/event.rs index e2a4eaa16e..f1eaa0d155 100644 --- a/src/sys/event.rs +++ b/src/sys/event.rs @@ -135,6 +135,8 @@ libc_bitflags!( NOTE_EXEC; NOTE_EXIT; #[cfg(any(target_os = "macos", target_os = "ios"))] + #[deprecated( since="0.14.0", note="Deprecated since OSX 10.9")] + #[allow(deprecated)] NOTE_EXIT_REPARENTED; #[cfg(any(target_os = "macos", target_os = "ios"))] NOTE_EXITSTATUS; @@ -183,6 +185,9 @@ libc_bitflags!( NOTE_PCTRLMASK; NOTE_PDATAMASK; #[cfg(any(target_os = "macos", target_os = "ios"))] + #[cfg(any(target_os = "macos", target_os = "ios"))] + #[deprecated( since="0.14.0", note="Deprecated since OSX 10.9")] + #[allow(deprecated)] NOTE_REAP; NOTE_RENAME; NOTE_REVOKE; diff --git a/src/unistd.rs b/src/unistd.rs index a41c1392be..85cec3da8c 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -828,6 +828,11 @@ pub fn execveat(dirfd: RawFd, pathname: &CString, args: &[CString], /// descriptors will remain identical after daemonizing. /// * `noclose = false`: The process' stdin, stdout, and stderr will point to /// `/dev/null` after daemonizing. +#[cfg_attr(any(target_os = "macos", target_os = "ios"), deprecated( + since="0.14.0", + note="Deprecated in MacOSX 10.5" +))] +#[cfg_attr(any(target_os = "macos", target_os = "ios"), allow(deprecated))] pub fn daemon(nochdir: bool, noclose: bool) -> Result<()> { let res = unsafe { libc::daemon(nochdir as c_int, noclose as c_int) }; Errno::result(res).map(drop) From 3453a8c6227bce298cb27f6fd7a1fc8be4bca697 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 3 Mar 2019 18:49:47 -0700 Subject: [PATCH 2/4] Fix test_thread_signal* test failures with Cargo 1.33.0 Previous versions of Cargo would create and destroy a new thread for each test. Cargo 1.33.0 instead creates a thread pool and reuses the same thread for multiple tests. Some Nix tests that changed the per-thread sigmask began to fail as a result, because they didn't do any cleanup. The easiest solution is to spawn a new thread for each of those tests. --- src/sys/signal.rs | 125 ++++++++++++++++++++++++++-------------------- 1 file changed, 71 insertions(+), 54 deletions(-) diff --git a/src/sys/signal.rs b/src/sys/signal.rs index 79a3ca1086..ff1c66376c 100644 --- a/src/sys/signal.rs +++ b/src/sys/signal.rs @@ -833,6 +833,7 @@ mod sigevent { #[cfg(test)] mod tests { + use std::thread; use super::*; #[test] @@ -894,104 +895,120 @@ mod tests { #[test] fn test_thread_signal_set_mask() { - let prev_mask = SigSet::thread_get_mask().expect("Failed to get existing signal mask!"); + thread::spawn(|| { + let prev_mask = SigSet::thread_get_mask() + .expect("Failed to get existing signal mask!"); - let mut test_mask = prev_mask; - test_mask.add(SIGUSR1); + let mut test_mask = prev_mask; + test_mask.add(SIGUSR1); - assert!(test_mask.thread_set_mask().is_ok()); - let new_mask = SigSet::thread_get_mask().expect("Failed to get new mask!"); + assert!(test_mask.thread_set_mask().is_ok()); + let new_mask = SigSet::thread_get_mask() + .expect("Failed to get new mask!"); - assert!(new_mask.contains(SIGUSR1)); - assert!(!new_mask.contains(SIGUSR2)); + assert!(new_mask.contains(SIGUSR1)); + assert!(!new_mask.contains(SIGUSR2)); - prev_mask.thread_set_mask().expect("Failed to revert signal mask!"); + prev_mask.thread_set_mask().expect("Failed to revert signal mask!"); + }).join().unwrap(); } #[test] fn test_thread_signal_block() { - let mut mask = SigSet::empty(); - mask.add(SIGUSR1); + thread::spawn(|| { + let mut mask = SigSet::empty(); + mask.add(SIGUSR1); - assert!(mask.thread_block().is_ok()); + assert!(mask.thread_block().is_ok()); - assert!(SigSet::thread_get_mask().unwrap().contains(SIGUSR1)); + assert!(SigSet::thread_get_mask().unwrap().contains(SIGUSR1)); + }).join().unwrap(); } #[test] fn test_thread_signal_unblock() { - let mut mask = SigSet::empty(); - mask.add(SIGUSR1); + thread::spawn(|| { + let mut mask = SigSet::empty(); + mask.add(SIGUSR1); - assert!(mask.thread_unblock().is_ok()); + assert!(mask.thread_unblock().is_ok()); - assert!(!SigSet::thread_get_mask().unwrap().contains(SIGUSR1)); + assert!(!SigSet::thread_get_mask().unwrap().contains(SIGUSR1)); + }).join().unwrap(); } #[test] fn test_thread_signal_swap() { - let mut mask = SigSet::empty(); - mask.add(SIGUSR1); - mask.thread_block().unwrap(); + thread::spawn(|| { + let mut mask = SigSet::empty(); + mask.add(SIGUSR1); + mask.thread_block().unwrap(); - assert!(SigSet::thread_get_mask().unwrap().contains(SIGUSR1)); + assert!(SigSet::thread_get_mask().unwrap().contains(SIGUSR1)); - let mut mask2 = SigSet::empty(); - mask2.add(SIGUSR2); + let mut mask2 = SigSet::empty(); + mask2.add(SIGUSR2); - let oldmask = mask2.thread_swap_mask(SigmaskHow::SIG_SETMASK).unwrap(); + let oldmask = mask2.thread_swap_mask(SigmaskHow::SIG_SETMASK) + .unwrap(); - assert!(oldmask.contains(SIGUSR1)); - assert!(!oldmask.contains(SIGUSR2)); + assert!(oldmask.contains(SIGUSR1)); + assert!(!oldmask.contains(SIGUSR2)); - assert!(SigSet::thread_get_mask().unwrap().contains(SIGUSR2)); + assert!(SigSet::thread_get_mask().unwrap().contains(SIGUSR2)); + }).join().unwrap(); } #[test] fn test_sigaction() { use libc; + thread::spawn(|| { + extern fn test_sigaction_handler(_: libc::c_int) {} + extern fn test_sigaction_action(_: libc::c_int, + _: *mut libc::siginfo_t, _: *mut libc::c_void) {} - extern fn test_sigaction_handler(_: libc::c_int) {} - extern fn test_sigaction_action(_: libc::c_int, - _: *mut libc::siginfo_t, _: *mut libc::c_void) {} - - let handler_sig = SigHandler::Handler(test_sigaction_handler); + let handler_sig = SigHandler::Handler(test_sigaction_handler); - let flags = SaFlags::SA_ONSTACK | SaFlags::SA_RESTART | SaFlags::SA_SIGINFO; + let flags = SaFlags::SA_ONSTACK | SaFlags::SA_RESTART | + SaFlags::SA_SIGINFO; - let mut mask = SigSet::empty(); - mask.add(SIGUSR1); + let mut mask = SigSet::empty(); + mask.add(SIGUSR1); - let action_sig = SigAction::new(handler_sig, flags, mask); + let action_sig = SigAction::new(handler_sig, flags, mask); - assert_eq!(action_sig.flags(), SaFlags::SA_ONSTACK | SaFlags::SA_RESTART); - assert_eq!(action_sig.handler(), handler_sig); + assert_eq!(action_sig.flags(), + SaFlags::SA_ONSTACK | SaFlags::SA_RESTART); + assert_eq!(action_sig.handler(), handler_sig); - mask = action_sig.mask(); - assert!(mask.contains(SIGUSR1)); - assert!(!mask.contains(SIGUSR2)); + mask = action_sig.mask(); + assert!(mask.contains(SIGUSR1)); + assert!(!mask.contains(SIGUSR2)); - let handler_act = SigHandler::SigAction(test_sigaction_action); - let action_act = SigAction::new(handler_act, flags, mask); - assert_eq!(action_act.handler(), handler_act); + let handler_act = SigHandler::SigAction(test_sigaction_action); + let action_act = SigAction::new(handler_act, flags, mask); + assert_eq!(action_act.handler(), handler_act); - let action_dfl = SigAction::new(SigHandler::SigDfl, flags, mask); - assert_eq!(action_dfl.handler(), SigHandler::SigDfl); + let action_dfl = SigAction::new(SigHandler::SigDfl, flags, mask); + assert_eq!(action_dfl.handler(), SigHandler::SigDfl); - let action_ign = SigAction::new(SigHandler::SigIgn, flags, mask); - assert_eq!(action_ign.handler(), SigHandler::SigIgn); + let action_ign = SigAction::new(SigHandler::SigIgn, flags, mask); + assert_eq!(action_ign.handler(), SigHandler::SigIgn); + }).join().unwrap(); } // TODO(#251): Re-enable after figuring out flakiness. #[cfg(not(any(target_os = "macos", target_os = "ios")))] #[test] fn test_sigwait() { - let mut mask = SigSet::empty(); - mask.add(SIGUSR1); - mask.add(SIGUSR2); - mask.thread_block().unwrap(); - - raise(SIGUSR1).unwrap(); - assert_eq!(mask.wait().unwrap(), SIGUSR1); + thread::spawn(|| { + let mut mask = SigSet::empty(); + mask.add(SIGUSR1); + mask.add(SIGUSR2); + mask.thread_block().unwrap(); + + raise(SIGUSR1).unwrap(); + assert_eq!(mask.wait().unwrap(), SIGUSR1); + }).join().unwrap(); } } From 719a04038c0377a8202038f68d77d100af1ca007 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 3 Mar 2019 18:52:30 -0700 Subject: [PATCH 3/4] Delete a useless unit test that never did anything. --- src/sys/signal.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/sys/signal.rs b/src/sys/signal.rs index ff1c66376c..70bd1d3196 100644 --- a/src/sys/signal.rs +++ b/src/sys/signal.rs @@ -887,12 +887,6 @@ mod tests { assert!(two_signals.contains(SIGUSR2)); } - // This test doesn't actually test get_mask functionality, see the set_mask test for that. - #[test] - fn test_thread_signal_get_mask() { - assert!(SigSet::thread_get_mask().is_ok()); - } - #[test] fn test_thread_signal_set_mask() { thread::spawn(|| { From 439b930047c56cdb76c7c66f9fe8703e9c2d1a5b Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Sun, 3 Mar 2019 18:52:51 -0700 Subject: [PATCH 4/4] Reenable test_sigwait on OSX It was disabled long ago and nobody remembered to reenable it. I'm guessing it's fixed by now. --- src/sys/signal.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/sys/signal.rs b/src/sys/signal.rs index 70bd1d3196..eeaabd0424 100644 --- a/src/sys/signal.rs +++ b/src/sys/signal.rs @@ -991,8 +991,6 @@ mod tests { }).join().unwrap(); } - // TODO(#251): Re-enable after figuring out flakiness. - #[cfg(not(any(target_os = "macos", target_os = "ios")))] #[test] fn test_sigwait() { thread::spawn(|| {