diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/ops/process.rs | 21 | ||||
-rw-r--r-- | runtime/ops/signal.rs | 7 |
2 files changed, 9 insertions, 19 deletions
diff --git a/runtime/ops/process.rs b/runtime/ops/process.rs index 1f7280d48..7b01916b4 100644 --- a/runtime/ops/process.rs +++ b/runtime/ops/process.rs @@ -257,7 +257,8 @@ async fn op_run_status( } #[cfg(unix)] -pub fn kill(pid: i32, signo: i32) -> Result<(), AnyError> { +pub fn kill(pid: i32, signal: &str) -> Result<(), AnyError> { + let signo = super::signal::signal_str_to_int(signal)?; use nix::sys::signal::{kill as unix_kill, Signal}; use nix::unistd::Pid; use std::convert::TryFrom; @@ -266,7 +267,7 @@ pub fn kill(pid: i32, signo: i32) -> Result<(), AnyError> { } #[cfg(not(unix))] -pub fn kill(pid: i32, signal: i32) -> Result<(), AnyError> { +pub fn kill(pid: i32, signal: &str) -> Result<(), AnyError> { use std::io::Error; use std::io::ErrorKind::NotFound; use winapi::shared::minwindef::DWORD; @@ -279,14 +280,10 @@ pub fn kill(pid: i32, signal: i32) -> Result<(), AnyError> { use winapi::um::processthreadsapi::TerminateProcess; use winapi::um::winnt::PROCESS_TERMINATE; - const SIGINT: i32 = 2; - const SIGKILL: i32 = 9; - const SIGTERM: i32 = 15; - - if !matches!(signal, SIGINT | SIGKILL | SIGTERM) { - Err(type_error("unsupported signal")) + if !matches!(signal, "SIGINT" | "SIGKILL" | "SIGTERM") { + Err(type_error(format!("Invalid signal: {}", signal))) } else if pid <= 0 { - Err(type_error("unsupported pid")) + Err(type_error("Invalid pid")) } else { let handle = unsafe { OpenProcess(PROCESS_TERMINATE, FALSE, pid as DWORD) }; if handle.is_null() { @@ -310,12 +307,10 @@ pub fn kill(pid: i32, signal: i32) -> Result<(), AnyError> { fn op_kill( state: &mut OpState, pid: i32, - signo: String, + signal: String, ) -> Result<(), AnyError> { super::check_unstable(state, "Deno.kill"); state.borrow_mut::<Permissions>().run.check_all()?; - - let signo = super::signal::signal_str_to_int(&signo)?; - kill(pid, signo)?; + kill(pid, &signal)?; Ok(()) } diff --git a/runtime/ops/signal.rs b/runtime/ops/signal.rs index 60d707027..eef72f511 100644 --- a/runtime/ops/signal.rs +++ b/runtime/ops/signal.rs @@ -169,15 +169,10 @@ pub fn signal_str_to_int(s: &str) -> Result<libc::c_int, AnyError> { "SIGINFO" => Ok(29), "SIGUSR1" => Ok(30), "SIGUSR2" => Ok(31), - _ => Err(type_error(format!("Invalid signal : {}", s))), + _ => Err(type_error(format!("Invalid signal: {}", s))), } } -#[cfg(target_os = "windows")] -pub fn signal_str_to_int(_s: &str) -> Result<libc::c_int, AnyError> { - Err(generic_error("not implemented")) -} - #[cfg(unix)] fn op_signal_bind( state: &mut OpState, |