summaryrefslogtreecommitdiff
path: root/runtime/ops/process.rs
diff options
context:
space:
mode:
authorLeo Kettmeir <crowlkats@toaxl.com>2022-05-15 05:57:09 +0200
committerGitHub <noreply@github.com>2022-05-15 05:57:09 +0200
commitb08b1da6f4550601eec23327bd40d17ad6a6b4e9 (patch)
treea9bf72e90ba98afdc5aa7067c79cf0093170e15a /runtime/ops/process.rs
parentc496639d5dc190b107222bc30462d67ddb86c223 (diff)
Revert "refactor(runtime): change from signal_str_to_int function to enum (#14539)" (#14606)
This reverts commit c496639d5dc190b107222bc30462d67ddb86c223.
Diffstat (limited to 'runtime/ops/process.rs')
-rw-r--r--runtime/ops/process.rs15
1 files changed, 9 insertions, 6 deletions
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::<Permissions>().run.check_all()?;
- kill(pid, signal)?;
+ kill(pid, &signal)?;
Ok(())
}