Skip to content

Commit 5cc2e19

Browse files
committed
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
1 parent 5729d0f commit 5cc2e19

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/unistd.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,7 +1633,8 @@ pub mod alarm {
16331633
//!
16341634
//! Scheduling an alarm and waiting for the signal:
16351635
//!
1636-
//! ```
1636+
#![cfg_attr(target_os = "redox", doc = " ```rust,ignore")]
1637+
#![cfg_attr(not(target_os = "redox"), doc = " ```rust")]
16371638
//! use std::time::{Duration, Instant};
16381639
//!
16391640
//! use nix::unistd::{alarm, pause};
@@ -1642,14 +1643,23 @@ pub mod alarm {
16421643
//! // We need to setup an empty signal handler to catch the alarm signal,
16431644
//! // otherwise the program will be terminated once the signal is delivered.
16441645
//! extern fn signal_handler(_: nix::libc::c_int) { }
1645-
//! unsafe { sigaction(Signal::SIGALRM, &SigAction::new(SigHandler::Handler(signal_handler), SaFlags::empty(), SigSet::empty())); }
1646+
//! let sa = SigAction::new(
1647+
//! SigHandler::Handler(signal_handler),
1648+
//! SaFlags::empty(),
1649+
//! SigSet::empty()
1650+
//! );
1651+
//! unsafe {
1652+
//! sigaction(Signal::SIGALRM, &sa);
1653+
//! }
16461654
//!
16471655
//! // Set an alarm for 1 second from now.
16481656
//! alarm::set(1);
16491657
//!
16501658
//! let start = Instant::now();
16511659
//! // Pause the process until the alarm signal is received.
1652-
//! pause();
1660+
//! let mut sigset = SigSet::empty();
1661+
//! sigset.add(Signal::SIGALRM);
1662+
//! sigset.wait();
16531663
//!
16541664
//! assert!(start.elapsed() >= Duration::from_secs(1));
16551665
//! ```

0 commit comments

Comments
 (0)