1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2026-01-20 04:01:06 +00:00

Use ChildExt to kill from timeout.rs

This commit is contained in:
Remi Rampin 2015-06-30 17:58:34 -04:00
parent cce3d5171d
commit d806ab4809
2 changed files with 8 additions and 6 deletions

1
src/timeout/deps.mk Normal file
View file

@ -0,0 +1 @@
DEPLIBS += time

View file

@ -12,6 +12,7 @@
extern crate getopts;
extern crate libc;
extern crate time;
use libc::pid_t;
use std::io::{ErrorKind, Write};
@ -28,6 +29,10 @@ mod parse_time;
#[path = "../common/signals.rs"]
mod signals;
#[path = "../common/process.rs"]
mod process;
use process::ChildExt;
extern {
pub fn setpgid(_: libc::pid_t, _: libc::pid_t) -> libc::c_int;
}
@ -127,9 +132,7 @@ fn timeout(cmdname: &str, args: &[String], duration: f64, signal: usize, kill_af
match process.wait() {
Ok(status) => status.code().unwrap_or_else(|| status.signal().unwrap()),
Err(_) => {
if unsafe { libc::funcs::posix88::signal::kill(process.id() as pid_t, signal as i32) } != 0 {
return ERR_EXIT_STATUS;
}
return_if_err!(ERR_EXIT_STATUS, process.send_signal(signal));
process.set_timeout(Some((kill_after * 1000f64) as u64));
match process.wait() {
Ok(status) => {
@ -144,9 +147,7 @@ fn timeout(cmdname: &str, args: &[String], duration: f64, signal: usize, kill_af
// XXX: this may not be right
return 124;
}
if unsafe { libc::funcs::posix88::signal::kill(process.id() as pid_t, signals::signal_by_name_or_value("KILL").unwrap() as i32) } != 0 {
return ERR_EXIT_STATUS;
}
return_if_err!(ERR_EXIT_STATUS, process.send_signal(signals::signal_by_name_or_value("KILL").unwrap()));
process.set_timeout(None);
return_if_err!(ERR_EXIT_STATUS, process.wait());
137