@@ -13,12 +13,8 @@ use tracing::{debug, instrument, warn};
1313// --- Add nix imports ---
1414#[ cfg( unix) ]
1515use nix:: sys:: signal:: { killpg, Signal } ;
16- #[ cfg( windows) ]
17- use windows_sys:: Win32 :: System :: Threading :: { OpenProcess , TerminateProcess , PROCESS_TERMINATE } ;
1816#[ cfg( unix) ]
1917use nix:: unistd:: Pid ;
20- #[ cfg( windows) ]
21- use windows_sys:: Win32 :: Foundation :: HANDLE ;
2218
2319// --- End add ---
2420
@@ -272,13 +268,12 @@ async fn handle_timeout_event(
272268 "Killing process group due to timeout"
273269 ) ;
274270 // Convert u32 PID to nix's Pid type (i32)
275- #[ cfg( unix) ]
276- let pid = Pid :: from_raw ( pid_u32 as i32 ) ;
277- #[ cfg( windows) ]
278- let pid = HANDLE :: from ( pid_u32 as * mut c_void ) ;
279271 // Send SIGKILL to the entire process group.
280272 // killpg takes the PID of any process in the group (usually the leader)
281273 // and signals the entire group associated with that process.
274+
275+ #[ cfg( unix) ]
276+ let pid = Pid :: from_raw ( pid_u32 as i32 ) ;
282277 #[ cfg( unix) ]
283278 match killpg ( pid, Signal :: SIGKILL ) {
284279 Ok ( ( ) ) => {
@@ -323,13 +318,16 @@ async fn handle_timeout_event(
323318 }
324319 #[ cfg( windows) ]
325320 {
321+ use std:: ffi:: c_void;
326322 use windows_sys:: Win32 :: Foundation :: { CloseHandle , HANDLE } ;
323+ use windows_sys:: Win32 :: Foundation :: INVALID_HANDLE_VALUE ;
327324 use windows_sys:: Win32 :: System :: Threading :: { OpenProcess , TerminateProcess , PROCESS_TERMINATE } ;
325+ use windows_sys:: Win32 :: Foundation :: BOOL ;
328326
329327 unsafe {
330328 // Open a handle to the process with termination privileges.
331- let handle: HANDLE = OpenProcess ( PROCESS_TERMINATE , false , pid_u32) ;
332- if handle. is_invalid ( ) {
329+ let handle: HANDLE = OpenProcess ( PROCESS_TERMINATE , BOOL :: from ( false ) , pid_u32) ;
330+ if handle == INVALID_HANDLE_VALUE {
333331 // Could not obtain a handle, perhaps the process already exited.
334332 let err = std:: io:: Error :: last_os_error ( ) ;
335333 warn ! ( pid = pid_u32, error = %err, "Failed to open process handle for termination (possibly already exited). Checking child status." ) ;
@@ -350,7 +348,7 @@ async fn handle_timeout_event(
350348 }
351349 } else {
352350 // Attempt to terminate the process.
353- if TerminateProcess ( handle, 1 ) . as_bool ( ) {
351+ if TerminateProcess ( handle, 1 ) . is_positive ( ) {
354352 debug ! ( pid = pid_u32, "Process terminated successfully via TerminateProcess." ) ;
355353 CloseHandle ( handle) ;
356354 Ok ( None )
0 commit comments