Skip to content

Commit 93ea848

Browse files
committed
block sigchild in popen
1 parent 15e4872 commit 93ea848

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/io/popen.ml

+13-3
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,18 @@ let kill_and_close_ (self : t) =
3838
: Thread.t);
3939

4040
(* kill zombies *)
41-
let code = try fst @@ Unix.waitpid [] self.pid with _ -> max_int in
41+
let code =
42+
try
43+
ignore (Unix.sigprocmask Unix.SIG_BLOCK [ Sys.sigchld ]);
44+
fst @@ Unix.waitpid [] self.pid
45+
with _ -> max_int
46+
in
4247
Fut.fulfill_idempotent self._st.promise_code @@ Ok code
4348
)
4449

4550
let run_ ?(env = Unix.environment ()) cmd args : t =
4651
(* block sigpipe *)
47-
ignore (Unix.sigprocmask Unix.SIG_BLOCK [ Sys.sigpipe ]);
52+
ignore (Unix.sigprocmask Unix.SIG_BLOCK [ Sys.sigpipe; Sys.sigchld ]);
4853
(* make pipes, to give the appropriate ends to the subprocess *)
4954
let stdout, p_stdout = Unix.pipe () in
5055
let stderr, p_stderr = Unix.pipe () in
@@ -87,7 +92,12 @@ let signal self s = Unix.kill self.pid s
8792

8893
let wait (self : t) : int =
8994
Log.debug (fun k -> k "(popen.wait %a)" pp self);
90-
let res = try snd @@ Unix.waitpid [] self.pid with _ -> Unix.WEXITED 0 in
95+
let res =
96+
try
97+
ignore (Unix.sigprocmask Unix.SIG_BLOCK [ Sys.sigchld ]);
98+
snd @@ Unix.waitpid [] self.pid
99+
with _ -> Unix.WEXITED 0
100+
in
91101
kill_and_close_ self;
92102
let res =
93103
match res with

0 commit comments

Comments
 (0)