mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user