Fix process force kill logic on Windows
This commit is contained in:
parent
18fdf4c5f9
commit
99af0c6437
@ -47,4 +47,4 @@ rust_rcon = { package = "rcon", version = "0.5", optional = true }
|
||||
libc = "0.2"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
winapi = { version = "0.3", features = ["winuser", "processthreadsapi", "handleapi"] }
|
||||
winapi = { version = "0.3", features = ["winuser", "processthreadsapi", "handleapi", "ntdef", "minwindef"] }
|
||||
|
@ -15,7 +15,7 @@ pub fn force_kill(pid: u32) -> bool {
|
||||
|
||||
#[cfg(windows)]
|
||||
unsafe {
|
||||
return windodws::force_kill(pid);
|
||||
return windows::force_kill(pid);
|
||||
}
|
||||
|
||||
unimplemented!("force killing Minecraft server process not implemented on this platform");
|
||||
|
@ -1,3 +1,5 @@
|
||||
use winapi::shared::minwindef::{FALSE, TRUE};
|
||||
use winapi::shared::ntdef::NULL;
|
||||
use winapi::um::handleapi::CloseHandle;
|
||||
use winapi::um::processthreadsapi::{OpenProcess, TerminateProcess};
|
||||
use winapi::um::winnt::PROCESS_TERMINATE;
|
||||
@ -7,7 +9,14 @@ use winapi::um::winnt::PROCESS_TERMINATE;
|
||||
/// This is unsafe because the PID isn't checked.
|
||||
pub unsafe fn force_kill(pid: u32) -> bool {
|
||||
debug!(target: "lazymc", "Sending force kill to {} to kill server", pid);
|
||||
let handle = OpenProcess(PROCESS_TERMINATE, false, pid);
|
||||
let mut ok = TerminateProcess(handle, 1);
|
||||
CloseHandle(handle) && ok
|
||||
let handle = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
|
||||
if handle == NULL {
|
||||
warn!(target: "lazymc", "Failed to open process handle in order to kill it", pid);
|
||||
return false;
|
||||
}
|
||||
|
||||
let terminated = TerminateProcess(handle, 1) == TRUE;
|
||||
let closed = CloseHandle(handle) == TRUE;
|
||||
|
||||
terminated && closed
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user