daemon: chroot: Fix long-standing possible deadlock.

The child (chrooted) process wrote its answer on the pipe and then
exited.  Meanwhile the parent waiting for the child to exit before
reading from the pipe.  Thus if the output was larger than a Linux
pipebuffer then the whole thing would deadlock.
This commit is contained in:
Richard W.M. Jones
2021-03-26 16:04:43 +00:00
parent 48a35c117e
commit 94e64b28be

View File

@@ -62,6 +62,10 @@ let f t func arg =
(* Parent. *)
close wfd;
let chan = in_channel_of_descr rfd in
let ret = input_value chan in
close_in chan;
let _, status = waitpid [] pid in
(match status with
| WEXITED 0 -> ()
@@ -76,10 +80,6 @@ let f t func arg =
failwithf "chroot %s stopped by signal %d" t.name i
);
let chan = in_channel_of_descr rfd in
let ret = input_value chan in
close_in chan;
match ret with
| Either ret -> ret
| Or exn -> raise exn