mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 02:48:24 +00:00
refactor(runtime): change from signal_str_to_int function to enum (#14539)
This commit is contained in:
parent
bd4256262a
commit
c496639d5d
3 changed files with 166 additions and 170 deletions
|
@ -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(())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue