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"
|
libc = "0.2"
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[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)]
|
#[cfg(windows)]
|
||||||
unsafe {
|
unsafe {
|
||||||
return windodws::force_kill(pid);
|
return windows::force_kill(pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
unimplemented!("force killing Minecraft server process not implemented on this platform");
|
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::handleapi::CloseHandle;
|
||||||
use winapi::um::processthreadsapi::{OpenProcess, TerminateProcess};
|
use winapi::um::processthreadsapi::{OpenProcess, TerminateProcess};
|
||||||
use winapi::um::winnt::PROCESS_TERMINATE;
|
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.
|
/// This is unsafe because the PID isn't checked.
|
||||||
pub unsafe fn force_kill(pid: u32) -> bool {
|
pub unsafe fn force_kill(pid: u32) -> bool {
|
||||||
debug!(target: "lazymc", "Sending force kill to {} to kill server", pid);
|
debug!(target: "lazymc", "Sending force kill to {} to kill server", pid);
|
||||||
let handle = OpenProcess(PROCESS_TERMINATE, false, pid);
|
let handle = OpenProcess(PROCESS_TERMINATE, FALSE, pid);
|
||||||
let mut ok = TerminateProcess(handle, 1);
|
if handle == NULL {
|
||||||
CloseHandle(handle) && ok
|
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