From a8661d1271b7e33c622212d66859233e162ca589 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Tue, 16 Jan 2024 15:08:32 +0000 Subject: [PATCH] CA-387588: Unixext.really_read: restart on EINTR MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- lib/xapi-stdext-unix/unixext.ml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/xapi-stdext-unix/unixext.ml b/lib/xapi-stdext-unix/unixext.ml index 20f20de8..4cf628d4 100644 --- a/lib/xapi-stdext-unix/unixext.ml +++ b/lib/xapi-stdext-unix/unixext.ml @@ -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 @@ -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 *)