diff --git a/src/main.rs b/src/main.rs index b548130f..a0d0b454 100644 --- a/src/main.rs +++ b/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>, signal: Signal, restart: bool if let Some(ref child) = *guard { if restart { - debug!("Stopping child process with {:?} signal", signal); child.signal(signal); } diff --git a/src/process.rs b/src/process.rs index bf3e6431..e0b95268 100644 --- a/src/process.rs +++ b/src/process.rs @@ -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) { diff --git a/src/signal.rs b/src/signal.rs index fde96009..751b1a30 100644 --- a/src/signal.rs +++ b/src/signal.rs @@ -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)]