From 5cc2e194a6f619db560e3250b9fc41111153ffa1 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Wed, 9 Dec 2020 20:34:33 -0700 Subject: 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 --- src/unistd.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src') 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)); //! ``` -- cgit v1.2.3