diff options
| author | Leo Kettmeir <crowlkats@toaxl.com> | 2022-05-14 14:10:39 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-14 14:10:39 +0200 |
| commit | c496639d5dc190b107222bc30462d67ddb86c223 (patch) | |
| tree | a307526bd733ca0dd55308f4f5bbb8b6e4c37ef1 /runtime/ops/process.rs | |
| parent | bd4256262a1091d43c18d069c724fa9b41c01b95 (diff) | |
refactor(runtime): change from signal_str_to_int function to enum (#14539)
Diffstat (limited to 'runtime/ops/process.rs')
| -rw-r--r-- | runtime/ops/process.rs | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/runtime/ops/process.rs b/runtime/ops/process.rs index ab303e210..d91ad2bab 100644 --- a/runtime/ops/process.rs +++ b/runtime/ops/process.rs @@ -288,16 +288,15 @@ async fn op_run_status( } #[cfg(unix)] -pub fn kill(pid: i32, signal: &str) -> Result<(), AnyError> { - let signo = super::signal::signal_str_to_int(signal)?; +pub fn kill(pid: i32, signal: super::signal::Signal) -> Result<(), AnyError> { use nix::sys::signal::{kill as unix_kill, Signal}; use nix::unistd::Pid; - let sig = Signal::try_from(signo)?; + let sig = Signal::try_from(signal as libc::c_int)?; unix_kill(Pid::from_raw(pid), Option::Some(sig)).map_err(AnyError::from) } #[cfg(not(unix))] -pub fn kill(pid: i32, signal: &str) -> Result<(), AnyError> { +pub fn kill(pid: i32, _signal: super::signal::Signal) -> Result<(), AnyError> { use deno_core::error::type_error; use std::io::Error; use std::io::ErrorKind::NotFound; @@ -311,9 +310,7 @@ pub fn kill(pid: i32, signal: &str) -> Result<(), AnyError> { use winapi::um::processthreadsapi::TerminateProcess; use winapi::um::winnt::PROCESS_TERMINATE; - if !matches!(signal, "SIGKILL" | "SIGTERM") { - Err(type_error(format!("Invalid signal: {}", signal))) - } else if pid <= 0 { + if pid <= 0 { Err(type_error("Invalid pid")) } else { let handle = unsafe { OpenProcess(PROCESS_TERMINATE, FALSE, pid as DWORD) }; @@ -339,9 +336,9 @@ pub fn kill(pid: i32, signal: &str) -> Result<(), AnyError> { fn op_kill( state: &mut OpState, pid: i32, - signal: String, + signal: super::signal::Signal, ) -> Result<(), AnyError> { state.borrow_mut::<Permissions>().run.check_all()?; - kill(pid, &signal)?; + kill(pid, signal)?; Ok(()) } |
