Skip to content

Commit

Permalink
Add SIGUSR1 and SIGUSR2
Browse files Browse the repository at this point in the history
Allows applications to handle SIGUSR1 and SIGUSR2.
  • Loading branch information
jwilm committed Apr 29, 2016
1 parent 4ed554d commit 0848e0e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
12 changes: 12 additions & 0 deletions examples/test_usr1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#[macro_use]
extern crate chan;
extern crate chan_signal;

use chan_signal::{Signal, kill_this};

fn main() {
let (s, r) = chan::sync(1);
chan_signal::notify_on(&s, Signal::USR1);
kill_this(Signal::USR1);
assert_eq!(r.recv(), Some(Signal::USR1));
}
10 changes: 9 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ use bit_set::BitSet;
use chan::Sender;
use libc::{
SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGABRT, SIGFPE, SIGKILL,
SIGSEGV, SIGPIPE, SIGALRM, SIGTERM,
SIGSEGV, SIGPIPE, SIGALRM, SIGTERM, SIGUSR1, SIGUSR2,
};
use libc::kill;
use libc::getpid;
Expand Down Expand Up @@ -241,6 +241,8 @@ pub enum Signal {
PIPE,
ALRM,
TERM,
USR1,
USR2,
#[doc(hidden)]
__NonExhaustiveMatch,
}
Expand All @@ -259,6 +261,8 @@ impl Signal {
SIGPIPE => Signal::PIPE,
SIGALRM => Signal::ALRM,
SIGTERM => Signal::TERM,
SIGUSR1 => Signal::USR1,
SIGUSR2 => Signal::USR2,
sig => panic!("unsupported signal number: {}", sig),
}
}
Expand All @@ -276,6 +280,8 @@ impl Signal {
Signal::PIPE => SIGPIPE,
Signal::ALRM => SIGALRM,
Signal::TERM => SIGTERM,
Signal::USR1 => SIGUSR1,
Signal::USR2 => SIGUSR2,
Signal::__NonExhaustiveMatch => unreachable!(),
}
}
Expand Down Expand Up @@ -306,6 +312,8 @@ impl SigSet {
set.add(SIGPIPE).unwrap();
set.add(SIGALRM).unwrap();
set.add(SIGTERM).unwrap();
set.add(SIGUSR1).unwrap();
set.add(SIGUSR2).unwrap();
set
}

Expand Down

0 comments on commit 0848e0e

Please sign in to comment.