Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SIGUSR1 and SIGUSR2 #6

Merged
merged 2 commits into from
Apr 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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