Actually use signal specified in --signal option
This commit is contained in:
parent
382981e22d
commit
4adde457dd
14
src/main.rs
14
src/main.rs
|
@ -62,17 +62,10 @@ fn main() {
|
|||
if let Some(lock) = weak_child.upgrade() {
|
||||
let strong = lock.read().unwrap();
|
||||
if let Some(ref child) = *strong {
|
||||
use nix::sys::signal::*;
|
||||
match sig {
|
||||
// TODO: This should be generalized to use new --signal flag
|
||||
// TODO: Not sure what this is doing tbh :(
|
||||
Signal::SIGTERM => {
|
||||
// TODO: Removed kill variable for now
|
||||
child.terminate();
|
||||
}
|
||||
Signal::SIGSTOP => child.pause(),
|
||||
Signal::SIGCONT => child.resume(),
|
||||
Signal::SIGCHLD => child.reap(),
|
||||
_ => debug!("Unhandled signal: {:?}", sig),
|
||||
SIGCHLD => child.reap(), // SIGCHLD is special, initiate reap()
|
||||
_ => child.signal(sig),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -197,7 +190,6 @@ fn wait_process(process: &RwLock<Option<Process>>, signal: Signal, restart: bool
|
|||
|
||||
if let Some(ref child) = *guard {
|
||||
if restart {
|
||||
debug!("Stopping child process with {:?} signal", signal);
|
||||
child.signal(signal);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ mod imp {
|
|||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
use std::sync::*;
|
||||
use nix::sys::signal::Signal;
|
||||
use signal::Signal;
|
||||
|
||||
pub struct Process {
|
||||
pgid: pid_t,
|
||||
|
@ -76,8 +76,24 @@ mod imp {
|
|||
}
|
||||
|
||||
pub fn signal(&self, signal: Signal) {
|
||||
// TODO: Sending dummy signal for now
|
||||
self.c_signal(SIGCONT);
|
||||
|
||||
// Convert from signal::Signal enum to libc::* c_int constants
|
||||
// TODO: This probably belongs into signal.rs (Maybe directly using libc::SIG*)
|
||||
let signo = match signal {
|
||||
Signal::SIGKILL => SIGKILL,
|
||||
Signal::SIGTERM => SIGTERM,
|
||||
Signal::SIGINT => SIGINT,
|
||||
Signal::SIGHUP => SIGHUP,
|
||||
Signal::SIGSTOP => SIGSTOP,
|
||||
Signal::SIGCONT => SIGCONT,
|
||||
Signal::SIGCHLD => SIGCHLD,
|
||||
Signal::SIGUSR1 => SIGUSR1,
|
||||
Signal::SIGUSR2 => SIGUSR2,
|
||||
_ => panic!("unsupported signal: {:?}", signal),
|
||||
};
|
||||
|
||||
debug!("Sending {:?} (int: {}) to child process", signal, signo);
|
||||
self.c_signal(signo);
|
||||
}
|
||||
|
||||
fn c_signal(&self, sig: c_int) {
|
||||
|
|
|
@ -6,8 +6,20 @@ lazy_static! {
|
|||
}
|
||||
|
||||
pub fn new(signal_name: &str) -> Signal {
|
||||
println!("Using signal {}", signal_name);
|
||||
Signal::SIGTERM
|
||||
use nix::sys::signal::*;
|
||||
|
||||
match signal_name {
|
||||
"SIGKILL" | "KILL" => SIGKILL,
|
||||
"SIGTERM" | "TERM" => SIGTERM,
|
||||
"SIGINT" | "INT" => SIGINT,
|
||||
"SIGHUP" | "HUP" => SIGHUP,
|
||||
"SIGSTOP" | "STOP" => SIGSTOP,
|
||||
"SIGCONT" | "CONT" => SIGCONT,
|
||||
"SIGCHLD" | "CHLD" => SIGCHLD,
|
||||
"SIGUSR1" | "USR1" => SIGUSR1,
|
||||
"SIGUSR2" | "USR2" => SIGUSR2,
|
||||
_ => panic!("unsupported signal: {}", signal_name),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
|
|
Loading…
Reference in New Issue