···11open Picos_std_structured
22open Picos_std_sync
33open Picos_std_finally
44-open Spawn
54open Jj_tui.Logging
6576module type t = sig
···115114 in
116115 (* This should ensure that all children processes are killed before we cleanup the pipes*)
117116 Flock.join_after @@ fun () ->
118118- let pid =
119119- Picos_io.Unix.create_process_env
120120- cmd
121121- (cmd :: args |> Array.of_list)
122122- (Unix.environment ())
123123- stdin_o
124124- stdout_i
125125- stderr_i
117117+ let isDone = ref false in
118118+ let@ pid =
119119+ finally
120120+ (fun pid ->
121121+ (* if the process didn't finish we will kill the process and then wait it's pid to release the pid*)
122122+ if not !isDone
123123+ then (
124124+ try
125125+ Unix.kill pid Sys.sigkill;
126126+ Unix.waitpid [ Unix.WUNTRACED ] pid |> ignore
127127+ with
128128+ | _ ->
129129+ ()))
130130+ (fun _ ->
131131+ Unix.create_process_env
132132+ cmd
133133+ (cmd :: args |> Array.of_list)
134134+ (Unix.environment ())
135135+ stdin_o
136136+ stdout_i
137137+ stderr_i)
126138 in
127127- let prom = Flock.fork_as_promise (fun () -> Picos_io.Unix.waitpid [] pid) in
139139+ let prom = Flock.fork_as_promise (fun () -> Unix.waitpid [] pid) in
128140 (* Close unused pipe ends in the parent process *)
129141 Unix.close stdout_i;
130142 Unix.close stdin_o;
···136148 let stdout = Promise.await stdout_prom in
137149 let stderr = Promise.await stderr_prom in
138150 let code, status = Promise.await prom in
151151+ isDone := true;
139152 (* let stderr = read_fd_to_end stderr_i in *)
140153 (* let stdout= ""in *)
141154 code, status, stdout, stderr
+2-1
jj_tui/lib/logging.ml
···9595 match Sys.os_type with
9696 | "Unix" ->
9797 (try
9898- let uname_in, _ = Unix.open_process_args "uname" [| "uname"; "-s" |] in
9898+ let uname_in = Unix.open_process_args_in "uname" [| "uname"; "-s" |] in
9999 let str = uname_in |> In_channel.input_all in
100100+ Unix.wait()|>ignore;
100101 Some (str |> String.lowercase_ascii |> String.trim)
101102 with
102103 | _ ->