Skip to content

Commit 37a8edf

Browse files
committed
fixup! Windows safe kill.
1 parent e404b85 commit 37a8edf

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

lib/olly_common/launch.ml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,16 @@ let exec_process (config : runtime_events_config) (args : string list) :
8787
(Fail (Printf.sprintf "executable %s not found" executable_filename))
8888
in
8989
let child_pid = get_process_id child_handle in
90-
(* On Windows Unix.kill takes a PID (uses OpenProcess) but Unix.waitpid
91-
takes the HANDLE returned by create_process — they are different
92-
values. On Unix the handle and PID coincide.
90+
(* OCaml's Unix module on Windows uses the value returned by
91+
create_process (a HANDLE) as its process identifier — both Unix.kill
92+
and Unix.waitpid expect that value, NOT the real OS PID from
93+
GetProcessId. On Unix the handle and PID coincide.
9394
9495
We poll waitpid with WNOHANG rather than blocking indefinitely: if
9596
the kill didn't take for any reason, hanging the test suite for
9697
hours is worse than reporting and moving on. *)
9798
let kill () =
98-
(try Unix.kill child_pid Sys.sigkill
99+
(try Unix.kill child_handle Sys.sigkill
99100
with Unix.Unix_error _ | Invalid_argument _ -> ());
100101
let deadline = Unix.gettimeofday () +. 5.0 in
101102
let rec wait () =
@@ -186,9 +187,12 @@ let attach_process (dir : string) (pid : int) : subprocess =
186187
in
187188
let alive () = is_process_alive pid
188189
and close () = Runtime_events.free_cursor cursor in
189-
(* Best-effort: we did not create the process, so we have no handle to
190-
waitpid on. Send the platform terminate signal and poll
191-
is_process_alive briefly. *)
190+
(* Best-effort: we did not create the process, so we have no handle.
191+
On Unix this kills via SIGKILL. On Windows this is effectively a
192+
no-op because OCaml's Unix.kill expects the value returned by
193+
create_process (a HANDLE), not an arbitrary PID — terminating an
194+
attached-to process there would need a Win32 OpenProcess +
195+
TerminateProcess C stub. *)
192196
let kill () =
193197
(try Unix.kill pid Sys.sigkill
194198
with Unix.Unix_error _ | Invalid_argument _ -> ());

0 commit comments

Comments
 (0)