mirror of
https://github.com/denoland/deno.git
synced 2025-09-28 13:14:48 +00:00
fix: subprocess kill support on windows (#12134)
This commit is contained in:
parent
0964685486
commit
ff3a17b72d
3 changed files with 46 additions and 36 deletions
|
|
@ -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(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue