summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlan Somers <asomers@gmail.com>2020-12-09 20:34:33 -0700
committerAlan Somers <asomers@gmail.com>2020-12-09 20:34:33 -0700
commit5cc2e194a6f619db560e3250b9fc41111153ffa1 (patch)
tree8ad3d9c1fe12324d576abcc938b875ed46eba67c /src
parent5729d0f391775c98699f0f92f8df6b7f5f49fc7d (diff)
downloadnix-5cc2e194a6f619db560e3250b9fc41111153ffa1.zip
Fix intermittency in the doc test for alarm
On Cirrus CI, this test would sometimes fail, probably due to pause being awoken by SIGRT_1. sigwait is a superior alternative to pause. Fixes #1354
Diffstat (limited to 'src')
-rw-r--r--src/unistd.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/unistd.rs b/src/unistd.rs
index a945ac26..0352f972 100644
--- a/src/unistd.rs
+++ b/src/unistd.rs
@@ -1633,7 +1633,8 @@ pub mod alarm {
//!
//! Scheduling an alarm and waiting for the signal:
//!
- //! ```
+#![cfg_attr(target_os = "redox", doc = " ```rust,ignore")]
+#![cfg_attr(not(target_os = "redox"), doc = " ```rust")]
//! use std::time::{Duration, Instant};
//!
//! use nix::unistd::{alarm, pause};
@@ -1642,14 +1643,23 @@ pub mod alarm {
//! // We need to setup an empty signal handler to catch the alarm signal,
//! // otherwise the program will be terminated once the signal is delivered.
//! extern fn signal_handler(_: nix::libc::c_int) { }
- //! unsafe { sigaction(Signal::SIGALRM, &SigAction::new(SigHandler::Handler(signal_handler), SaFlags::empty(), SigSet::empty())); }
+ //! let sa = SigAction::new(
+ //! SigHandler::Handler(signal_handler),
+ //! SaFlags::empty(),
+ //! SigSet::empty()
+ //! );
+ //! unsafe {
+ //! sigaction(Signal::SIGALRM, &sa);
+ //! }
//!
//! // Set an alarm for 1 second from now.
//! alarm::set(1);
//!
//! let start = Instant::now();
//! // Pause the process until the alarm signal is received.
- //! pause();
+ //! let mut sigset = SigSet::empty();
+ //! sigset.add(Signal::SIGALRM);
+ //! sigset.wait();
//!
//! assert!(start.elapsed() >= Duration::from_secs(1));
//! ```