chore(signal): Move alarm function and adding the todo
This commit is contained in:
@@ -4,9 +4,8 @@ use crate::{
|
||||
header::{
|
||||
bits_time::timespec,
|
||||
signal::{sigaction, siginfo_t, sigset_t, sigval, stack_t},
|
||||
sys_time::{self, itimerval},
|
||||
sys_time::itimerval,
|
||||
},
|
||||
platform,
|
||||
};
|
||||
|
||||
pub trait PalSignal: Pal {
|
||||
@@ -22,31 +21,7 @@ pub trait PalSignal: Pal {
|
||||
|
||||
fn setitimer(which: c_int, new: &itimerval, old: Option<&mut itimerval>) -> Result<()>;
|
||||
|
||||
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/alarm.html>.
|
||||
///
|
||||
/// Default implementation uses setitimer(ITIMER_REAL). Platforms that do not
|
||||
/// support setitimer (e.g. Redox) must override this.
|
||||
fn alarm(seconds: c_uint) -> c_uint {
|
||||
use crate::header::sys_select::timeval;
|
||||
|
||||
let timer = itimerval {
|
||||
it_value: timeval {
|
||||
tv_sec: time_t::from(seconds),
|
||||
tv_usec: 0,
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
let mut otimer = itimerval::default();
|
||||
|
||||
let errno_backup = platform::ERRNO.get();
|
||||
let secs = if Self::setitimer(sys_time::ITIMER_REAL, &timer, Some(&mut otimer)).is_err() {
|
||||
0
|
||||
} else {
|
||||
otimer.it_value.tv_sec as c_uint + if otimer.it_value.tv_usec > 0 { 1 } else { 0 }
|
||||
};
|
||||
platform::ERRNO.set(errno_backup);
|
||||
secs
|
||||
}
|
||||
fn alarm(seconds: c_uint) -> c_uint;
|
||||
|
||||
fn sigaction(sig: c_int, act: Option<&sigaction>, oact: Option<&mut sigaction>) -> Result<()>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user