Clerk: fix finalisation on exit

We have temporary files to remove upon `ninja` completion so it's not a good
idea to `exec` without fork. This patch ensures `/tmp/clerk_*.ninja` files
aren't left in `/tmp`.
This commit is contained in:
Louis Gesbert 2024-05-08 12:23:35 +02:00
parent affa45c115
commit 1efdf4262d

View File

@ -935,7 +935,16 @@ let ninja_cmdline ninja_flags nin_file targets =
let run_ninja ~clean_up_env cmdline =
let cmd = List.hd cmdline in
let env = if clean_up_env then cleaned_up_env () else Unix.environment () in
Unix.execvpe cmd (Array.of_list cmdline) env
let npid =
Unix.create_process_env cmd (Array.of_list cmdline) env Unix.stdin
Unix.stdout Unix.stderr
in
let return_code =
match Unix.waitpid [] npid with
| _, Unix.WEXITED n -> n
| _, (Unix.WSIGNALED n | Unix.WSTOPPED n) -> 128 - n
in
raise (Catala_utils.Cli.Exit_with return_code)
open Cmdliner