terminal user interface to jujutsu. Focused on speed and clarity
9
fork

Configure Feed

Select the types of activity you want to include in your feed.

ensure file descriptors are closed and mutex is unlocked

+31 -18
+31 -18
jj_tui/bin/jj_process.ml
··· 103 103 104 104 let picos_process cmd args = 105 105 let open Picos_io in 106 + let closed_one_end = ref false in 107 + let dispose fd = if not !closed_one_end then Unix.close fd in 106 108 let@ stdout_o, stdout_i = 107 - finally (fun (o, i) -> Unix.close o) (Picos_io.Unix.pipe ~cloexec:true) 109 + finally 110 + (fun (o, i) -> 111 + Unix.close o; 112 + dispose i) 113 + (Picos_io.Unix.pipe ~cloexec:true) 108 114 in 109 115 let@ stdin_o, stdin_i = 110 - finally (fun (o, i) -> Unix.close i) (Picos_io.Unix.pipe ~cloexec:true) 116 + finally 117 + (fun (o, i) -> 118 + Unix.close i; 119 + dispose o) 120 + (Picos_io.Unix.pipe ~cloexec:true) 111 121 in 112 122 let@ stderr_o, stderr_i = 113 - finally (fun (o, i) -> Unix.close o) (Picos_io.Unix.pipe ~cloexec:true) 123 + finally 124 + (fun (o, i) -> 125 + Unix.close o; 126 + dispose i) 127 + (Picos_io.Unix.pipe ~cloexec:true) 114 128 in 115 129 (* This should ensure that all children processes are killed before we cleanup the pipes*) 116 130 Flock.join_after @@ fun () -> ··· 118 132 let@ pid = 119 133 finally 120 134 (fun pid -> 121 - (* if the process didn't finish we will kill the process and then wait it's pid to release the pid*) 122 - if not !isDone 123 - then ( 124 - try 125 - [%log debug "Cleaning up cancelled command %s" (args|>String.concat " " )]; 126 - Unix.kill pid Sys.sigkill; 127 - Unix.waitpid [ Unix.WUNTRACED ] pid |> ignore 128 - with 129 - | _ -> 130 - ())) 135 + (* if the process didn't finish we will kill the process and then wait it's pid to release the pid*) 136 + if not !isDone 137 + then ( 138 + try 139 + [%log debug "Cleaning up cancelled command %s" (args |> String.concat " ")]; 140 + Unix.kill pid Sys.sigkill; 141 + Unix.waitpid [ Unix.WUNTRACED ] pid |> ignore 142 + with 143 + | _ -> 144 + ())) 131 145 (fun _ -> 132 146 Unix.create_process_env 133 147 cmd ··· 142 156 Unix.close stdout_i; 143 157 Unix.close stdin_o; 144 158 Unix.close stderr_i; 145 - 146 - Unix.set_nonblock stdout_o; 147 - Unix.set_nonblock stderr_o; 159 + closed_one_end := true; 148 160 let stdout_prom = read_fd_to_end stdout_o in 149 161 let stderr_prom = read_fd_to_end stderr_o in 150 162 let stdout = Promise.await stdout_prom in ··· 204 216 (List.concat 205 217 [ 206 218 args 207 - ; ["--no-pager"] 219 + ; [ "--no-pager" ] 208 220 ; (if snapshot then [] else [ "--ignore-working-copy" ]) 209 221 ; (if color then [ "--color"; "always" ] else [ "--color"; "never" ]) 210 222 ]) 211 223 with 212 224 | Picos_std_structured.Control.Terminate as e -> 213 - [%log debug "Terminated cmmand: %s" (args|>String.concat " " )]; 225 + [%log debug "Terminated command: %s" (args |> String.concat " ")]; 226 + if locked then Mutex.unlock access_lock; 214 227 raise e 215 228 | e -> 216 229 [%log warn "Exception running jj: %s" (Printexc.to_string e)];