Skip to content

Commit

Permalink
Merge branch 'master' of github.com:vorner/signal-hook
Browse files Browse the repository at this point in the history
  • Loading branch information
vorner committed Mar 31, 2024
2 parents 1fa30e4 + b65232e commit afa5feb
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.3.17

* Fix race condition leading into a panic in SignalsInfo::forever (#148).

# 0.3.16

* Fix compilation on OpenBSD (#147).
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "signal-hook"
version = "0.3.16"
version = "0.3.17"
authors = [
"Michal 'vorner' Vaner <vorner@vorner.cz>",
"Thomas Himmelstoss <thimm@posteo.de>",
Expand Down
2 changes: 1 addition & 1 deletion src/iterator/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ impl<SD, E: Exfiltrator> SignalIterator<SD, E> {
/// [`PollResult::Pending`] and assume it will be called again at a later point in time.
/// The callback may be called any number of times by this function.
///
/// If the iterator was closed by the [`close`][Handle::close] method of the associtated
/// If the iterator was closed by the [`close`][Handle::close] method of the associated
/// [`Handle`] this method will return [`PollResult::Closed`].
pub fn poll_signal<R, F>(&mut self, has_signals: &mut F) -> PollResult<E::Output>
where
Expand Down
23 changes: 13 additions & 10 deletions src/iterator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,16 +302,19 @@ impl<'a, E: Exfiltrator> Iterator for Forever<'a, E> {
type Item = E::Output;

fn next(&mut self) -> Option<E::Output> {
match self.0.poll_signal(&mut SignalsInfo::<E>::has_signals) {
PollResult::Signal(result) => Some(result),
PollResult::Closed => None,
PollResult::Pending => unreachable!(
"Because of the blocking has_signals method the \
poll_signal method never returns Poll::Pending but blocks until a signal arrived"
),
// Users can't manipulate the internal file descriptors and the way we use them
// shouldn't produce any errors. So it is OK to panic.
PollResult::Err(error) => panic!("Unexpected error: {}", error),
loop {
match self.0.poll_signal(&mut SignalsInfo::<E>::has_signals) {
PollResult::Signal(result) => break Some(result),
PollResult::Closed => break None,
// In theory, the poll_signal should not return PollResult::Pending. Nevertheless,
// there's a race condition - if the other side closes the pipe/socket after
// checking for it being closed, then the `read` there returns 0 as EOF. That
// appears as pending here. Next time we should get Closed.
PollResult::Pending => continue,
// Users can't manipulate the internal file descriptors and the way we use them
// shouldn't produce any errors. So it is OK to panic.
PollResult::Err(error) => panic!("Unexpected error: {}", error),
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
//! thing. It can register for a set of signals and produce them one by one, in a blocking manner.
//! You can reserve a thread for handling them as they come. If you want something asynchronous,
//! there are adaptor crates for the most common asynchronous runtimes. The module also contains
//! ways to build iterators that produce a bit more information that just the signal number.
//! ways to build iterators that produce a bit more information than just the signal number.
//!
//! The [`flag`] module contains routines to set a flag based on incoming signals and to do
//! certain actions inside the signal handlers based on the flags (the flags can also be
Expand Down

0 comments on commit afa5feb

Please sign in to comment.