Skip to content

Fix intermittency in the doc test for alarm #1355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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));
//! ```
Expand Down