Skip to content

Commit afa5feb

Browse files
committed
Merge branch 'master' of github.com:vorner/signal-hook
2 parents 1fa30e4 + b65232e commit afa5feb

File tree

6 files changed

+21
-14
lines changed

6 files changed

+21
-14
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.3.17
2+
3+
* Fix race condition leading into a panic in SignalsInfo::forever (#148).
4+
15
# 0.3.16
26

37
* Fix compilation on OpenBSD (#147).

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "signal-hook"
3-
version = "0.3.16"
3+
version = "0.3.17"
44
authors = [
55
"Michal 'vorner' Vaner <[email protected]>",
66
"Thomas Himmelstoss <[email protected]>",

src/iterator/backend.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ impl<SD, E: Exfiltrator> SignalIterator<SD, E> {
446446
/// [`PollResult::Pending`] and assume it will be called again at a later point in time.
447447
/// The callback may be called any number of times by this function.
448448
///
449-
/// If the iterator was closed by the [`close`][Handle::close] method of the associtated
449+
/// If the iterator was closed by the [`close`][Handle::close] method of the associated
450450
/// [`Handle`] this method will return [`PollResult::Closed`].
451451
pub fn poll_signal<R, F>(&mut self, has_signals: &mut F) -> PollResult<E::Output>
452452
where

src/iterator/mod.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -302,16 +302,19 @@ impl<'a, E: Exfiltrator> Iterator for Forever<'a, E> {
302302
type Item = E::Output;
303303

304304
fn next(&mut self) -> Option<E::Output> {
305-
match self.0.poll_signal(&mut SignalsInfo::<E>::has_signals) {
306-
PollResult::Signal(result) => Some(result),
307-
PollResult::Closed => None,
308-
PollResult::Pending => unreachable!(
309-
"Because of the blocking has_signals method the \
310-
poll_signal method never returns Poll::Pending but blocks until a signal arrived"
311-
),
312-
// Users can't manipulate the internal file descriptors and the way we use them
313-
// shouldn't produce any errors. So it is OK to panic.
314-
PollResult::Err(error) => panic!("Unexpected error: {}", error),
305+
loop {
306+
match self.0.poll_signal(&mut SignalsInfo::<E>::has_signals) {
307+
PollResult::Signal(result) => break Some(result),
308+
PollResult::Closed => break None,
309+
// In theory, the poll_signal should not return PollResult::Pending. Nevertheless,
310+
// there's a race condition - if the other side closes the pipe/socket after
311+
// checking for it being closed, then the `read` there returns 0 as EOF. That
312+
// appears as pending here. Next time we should get Closed.
313+
PollResult::Pending => continue,
314+
// Users can't manipulate the internal file descriptors and the way we use them
315+
// shouldn't produce any errors. So it is OK to panic.
316+
PollResult::Err(error) => panic!("Unexpected error: {}", error),
317+
}
315318
}
316319
}
317320
}

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
//! thing. It can register for a set of signals and produce them one by one, in a blocking manner.
5555
//! You can reserve a thread for handling them as they come. If you want something asynchronous,
5656
//! there are adaptor crates for the most common asynchronous runtimes. The module also contains
57-
//! ways to build iterators that produce a bit more information that just the signal number.
57+
//! ways to build iterators that produce a bit more information than just the signal number.
5858
//!
5959
//! The [`flag`] module contains routines to set a flag based on incoming signals and to do
6060
//! certain actions inside the signal handlers based on the flags (the flags can also be

0 commit comments

Comments
 (0)