[Ada] Improve detection of end of the process by GNAT.Expect

Message ID 20190821083143.GA71923@adacore.com
State New
Headers show
Series
  • [Ada] Improve detection of end of the process by GNAT.Expect
Related show

Commit Message

Pierre-Marie de Rodat Aug. 21, 2019, 8:31 a.m.
'read' system call may be interrupted by signal with 'errno' is set to
EINTER. In this case, re-try a few times.

Tested on x86_64-pc-linux-gnu, committed on trunk

2019-08-21  Vadim Godunko  <godunko@adacore.com>

gcc/ada/

	* libgnat/g-expect.adb (Expect_Internal): Attempt to read
	several times when 'read' returns non-positive.

Patch

--- gcc/ada/libgnat/g-expect.adb
+++ gcc/ada/libgnat/g-expect.adb
@@ -692,15 +692,21 @@  package body GNAT.Expect is
                            Buffer_Size := 4096;
                         end if;
 
-                        N := Read (Descriptors (D).Output_Fd, Buffer'Address,
-                                   Buffer_Size);
+                        --  Read may be interrupted on Linux by a signal and
+                        --  need to be repeated. We don't want to check for
+                        --  errno = EINTER, so just attempt to read a few
+                        --  times.
+
+                        for J in 1 .. 3 loop
+                           N := Read (Descriptors (D).Output_Fd,
+                                      Buffer'Address, Buffer_Size);
+
+                           exit when N > 0;
+                        end loop;
 
                         --  Error or End of file
 
                         if N <= 0 then
-                           --  ??? Note that ddd tries again up to three times
-                           --  in that case. See LiterateA.C:174
-
                            Close (Descriptors (D).Input_Fd);
                            Descriptors (D).Input_Fd := Invalid_FD;
                            Result := Expect_Process_Died;