Optional signal value for kill on timeouts in TimeoutForkserverExecutor (#461)
* Optional signal value to kill forked processes on timeout * Cargo format * Properly initialize TimeoutForkserverExecutor * Added with_signal constructor * Removed duplicate code
This commit is contained in:
parent
e6f2f2d0b2
commit
5ac3cd6b5a
@ -378,14 +378,25 @@ pub trait HasForkserver {
|
||||
pub struct TimeoutForkserverExecutor<E: Debug> {
|
||||
executor: E,
|
||||
timeout: TimeSpec,
|
||||
signal: Signal,
|
||||
}
|
||||
|
||||
impl<E: Debug> TimeoutForkserverExecutor<E> {
|
||||
/// Create a new [`TimeoutForkserverExecutor`]
|
||||
pub fn new(executor: E, exec_tmout: Duration) -> Result<Self, Error> {
|
||||
let signal = Signal::SIGKILL;
|
||||
Self::with_signal(executor, exec_tmout, signal)
|
||||
}
|
||||
|
||||
/// Create a new [`TimeoutForkserverExecutor`] that sends a user-defined signal to the timed-out process
|
||||
pub fn with_signal(executor: E, exec_tmout: Duration, signal: Signal) -> Result<Self, Error> {
|
||||
let milli_sec = exec_tmout.as_millis() as i64;
|
||||
let timeout = TimeSpec::milliseconds(milli_sec);
|
||||
Ok(Self { executor, timeout })
|
||||
Ok(Self {
|
||||
executor,
|
||||
timeout,
|
||||
signal,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -466,7 +477,7 @@ where
|
||||
self.executor.forkserver_mut().set_last_run_timed_out(1);
|
||||
|
||||
// We need to kill the child in case he has timed out, or we can't get the correct pid in the next call to self.executor.forkserver_mut().read_st()?
|
||||
let _ = kill(self.executor.forkserver().child_pid(), Signal::SIGKILL);
|
||||
let _ = kill(self.executor.forkserver().child_pid(), self.signal);
|
||||
let (recv_status_len, _) = self.executor.forkserver_mut().read_st()?;
|
||||
if recv_status_len != 4 {
|
||||
return Err(Error::Forkserver(
|
||||
|
Loading…
x
Reference in New Issue
Block a user