1
0
mirror of https://github.com/romanz/electrs.git synced 2024-11-19 09:54:09 +01:00

Merge branch 'handle-sigusr1'

This commit is contained in:
Roman Zeyde 2020-06-17 08:41:35 +03:00
commit 7125eba95e
No known key found for this signature in database
GPG Key ID: 87CAE5FA46917CBB

View File

@ -27,12 +27,22 @@ fn notify(signals: &[i32]) -> channel::Receiver<i32> {
impl Waiter {
pub fn start() -> Waiter {
Waiter {
receiver: notify(&[signal_hook::SIGINT, signal_hook::SIGTERM]),
receiver: notify(&[
signal_hook::SIGINT,
signal_hook::SIGTERM,
signal_hook::SIGUSR1, // allow external triggering (e.g. via bitcoind `blocknotify`)
]),
}
}
pub fn wait(&self, duration: Duration) -> Result<()> {
match self.receiver.recv_timeout(duration) {
Ok(sig) => bail!(ErrorKind::Interrupt(sig)),
Ok(sig) => {
trace!("notified via SIG{}", sig);
if sig != signal_hook::SIGUSR1 {
bail!(ErrorKind::Interrupt(sig))
};
Ok(())
}
Err(RecvTimeoutError::Timeout) => Ok(()),
Err(RecvTimeoutError::Disconnected) => bail!("signal hook channel disconnected"),
}