Skip to content

Commit

Permalink
Merge pull request #6 from jwilm/sigusr
Browse files Browse the repository at this point in the history
Add SIGUSR1 and SIGUSR2
  • Loading branch information
BurntSushi committed Apr 29, 2016
2 parents 0720d92 + 0848e0e commit 884cdad
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/test_many.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn main() {
chan_signal::notify_on(&s1, Signal::HUP);
chan_signal::notify_on(&s2, Signal::TERM);
kill_this(Signal::HUP);
kill_this(Signal::TERM);
assert_eq!(r1.recv(), Some(Signal::HUP));
kill_this(Signal::TERM);
assert_eq!(r2.recv(), Some(Signal::TERM));
}
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 884cdad

Please sign in to comment.