diff options
author | Fletcher Woodruff <fletcherw@chromium.org> | 2019-10-02 13:11:34 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-10-03 06:57:34 +0000 |
commit | 82ff397489cc9fcc6bee1cdc98aa5eede18f8978 (patch) | |
tree | 85fdae43df3cc74ef018c3a8eb3c2c6f91d7970c /sys_util | |
parent | f9b035d50c431c2a544ad1cb91ca5121165ae7aa (diff) | |
download | crosvm-82ff397489cc9fcc6bee1cdc98aa5eede18f8978.tar crosvm-82ff397489cc9fcc6bee1cdc98aa5eede18f8978.tar.gz crosvm-82ff397489cc9fcc6bee1cdc98aa5eede18f8978.tar.bz2 crosvm-82ff397489cc9fcc6bee1cdc98aa5eede18f8978.tar.lz crosvm-82ff397489cc9fcc6bee1cdc98aa5eede18f8978.tar.xz crosvm-82ff397489cc9fcc6bee1cdc98aa5eede18f8978.tar.zst crosvm-82ff397489cc9fcc6bee1cdc98aa5eede18f8978.zip |
sys_util: allow adding handlers for all signals
Currently, sys_util's register_signal_handler only permits handlers for real-time signals. Rename that function to register_rt_signal_handler and add a new register_signal_handler that supports all signals, then update references to the old name. BUG=chromium:1008990 TEST=builds Change-Id: I455e14c562cd1f2ca4b308b4e38c503845321926 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1836185 Tested-by: Fletcher Woodruff <fletcherw@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org> Commit-Queue: Fletcher Woodruff <fletcherw@chromium.org>
Diffstat (limited to 'sys_util')
-rw-r--r-- | sys_util/src/signal.rs | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/sys_util/src/signal.rs b/sys_util/src/signal.rs index 821f0f6..fee0a99 100644 --- a/sys_util/src/signal.rs +++ b/sys_util/src/signal.rs @@ -90,21 +90,15 @@ pub fn SIGRTMAX() -> c_int { unsafe { __libc_current_sigrtmax() } } -fn valid_signal_num(num: c_int) -> bool { +fn valid_rt_signal_num(num: c_int) -> bool { num >= SIGRTMIN() && num <= SIGRTMAX() } /// Registers `handler` as the signal handler of signum `num`. /// -/// The value of `num` must be within [`SIGRTMIN`, `SIGRTMAX`] range. -/// /// This is considered unsafe because the given handler will be called asynchronously, interrupting /// whatever the thread was doing and therefore must only do async-signal-safe operations. pub unsafe fn register_signal_handler(num: c_int, handler: extern "C" fn()) -> errno::Result<()> { - if !valid_signal_num(num) { - return Err(errno::Error::new(EINVAL)); - } - let mut sigact: sigaction = mem::zeroed(); sigact.sa_flags = SA_RESTART; sigact.sa_sigaction = handler as *const () as usize; @@ -117,6 +111,23 @@ pub unsafe fn register_signal_handler(num: c_int, handler: extern "C" fn()) -> e Ok(()) } +/// Registers `handler` as the signal handler for the real-time signal with signum `num`. +/// +/// The value of `num` must be within [`SIGRTMIN`, `SIGRTMAX`] range. +/// +/// This is considered unsafe because the given handler will be called asynchronously, interrupting +/// whatever the thread was doing and therefore must only do async-signal-safe operations. +pub unsafe fn register_rt_signal_handler( + num: c_int, + handler: extern "C" fn(), +) -> errno::Result<()> { + if !valid_rt_signal_num(num) { + return Err(errno::Error::new(EINVAL)); + } + + register_signal_handler(num, handler) +} + /// Creates `sigset` from an array of signal numbers. /// /// This is a helper function used when we want to manipulate signals. @@ -260,7 +271,7 @@ pub unsafe trait Killable { /// /// The value of `num` must be within [`SIGRTMIN`, `SIGRTMAX`] range. fn kill(&self, num: c_int) -> errno::Result<()> { - if !valid_signal_num(num) { + if !valid_rt_signal_num(num) { return Err(errno::Error::new(EINVAL)); } |