Skip to content

Commit

Permalink
CA-387588: Unixext.really_read: restart on EINTR
Browse files Browse the repository at this point in the history
To reproduce a forkexecd unit test failure I've run it under 'rr'.
This caused a different failure: EINTR from read.

Unixext already has code to defend against EINTR on write, but not on read: add missing loop.

Signed-off-by: Edwin Török <[email protected]>
  • Loading branch information
edwintorok authored and lindig committed Jan 17, 2024
1 parent 7c5c22b commit a8661d1
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions lib/xapi-stdext-unix/unixext.ml
Original file line number Diff line number Diff line change
Expand Up @@ -462,19 +462,6 @@ let proxy (a : Unix.file_descr) (b : Unix.file_descr) =
try Unix.close b with _ -> ()
)

let rec really_read fd string off n =
if n = 0 then
()
else
let m = Unix.read fd string off n in
if m = 0 then raise End_of_file ;
really_read fd string (off + m) (n - m)

let really_read_string fd length =
let buf = Bytes.make length '\000' in
really_read fd buf 0 length ;
Bytes.unsafe_to_string buf

let try_read_string ?limit fd =
let buf = Buffer.create 0 in
let chunk = match limit with None -> 4096 | Some x -> x in
Expand Down Expand Up @@ -523,6 +510,19 @@ and really_write fd buffer offset len =
let really_write_string fd string =
really_write fd string 0 (String.length string)

let rec really_read fd string off n =
if n = 0 then
()
else
let m = restart_on_EINTR (Unix.read fd string off) n in
if m = 0 then raise End_of_file ;
really_read fd string (off + m) (n - m)

let really_read_string fd length =
let buf = Bytes.make length '\000' in
really_read fd buf 0 length ;
Bytes.unsafe_to_string buf

(* --------------------------------------------------------------------------------------- *)
(* Functions to read and write to/from a file descriptor with a given latest response time *)

Expand Down

0 comments on commit a8661d1

Please sign in to comment.