From b08b1da6f4550601eec23327bd40d17ad6a6b4e9 Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Sun, 15 May 2022 05:57:09 +0200 Subject: Revert "refactor(runtime): change from signal_str_to_int function to enum (#14539)" (#14606) This reverts commit c496639d5dc190b107222bc30462d67ddb86c223. --- runtime/ops/process.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'runtime/ops/process.rs') diff --git a/runtime/ops/process.rs b/runtime/ops/process.rs index d91ad2bab..ab303e210 100644 --- a/runtime/ops/process.rs +++ b/runtime/ops/process.rs @@ -288,15 +288,16 @@ async fn op_run_status( } #[cfg(unix)] -pub fn kill(pid: i32, signal: super::signal::Signal) -> 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; - let sig = Signal::try_from(signal as libc::c_int)?; + let sig = Signal::try_from(signo)?; unix_kill(Pid::from_raw(pid), Option::Some(sig)).map_err(AnyError::from) } #[cfg(not(unix))] -pub fn kill(pid: i32, _signal: super::signal::Signal) -> Result<(), AnyError> { +pub fn kill(pid: i32, signal: &str) -> Result<(), AnyError> { use deno_core::error::type_error; use std::io::Error; use std::io::ErrorKind::NotFound; @@ -310,7 +311,9 @@ pub fn kill(pid: i32, _signal: super::signal::Signal) -> Result<(), AnyError> { use winapi::um::processthreadsapi::TerminateProcess; use winapi::um::winnt::PROCESS_TERMINATE; - if pid <= 0 { + if !matches!(signal, "SIGKILL" | "SIGTERM") { + Err(type_error(format!("Invalid signal: {}", signal))) + } else if pid <= 0 { Err(type_error("Invalid pid")) } else { let handle = unsafe { OpenProcess(PROCESS_TERMINATE, FALSE, pid as DWORD) }; @@ -336,9 +339,9 @@ pub fn kill(pid: i32, _signal: super::signal::Signal) -> Result<(), AnyError> { fn op_kill( state: &mut OpState, pid: i32, - signal: super::signal::Signal, + signal: String, ) -> Result<(), AnyError> { state.borrow_mut::().run.check_all()?; - kill(pid, signal)?; + kill(pid, &signal)?; Ok(()) } -- cgit v1.2.3