]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[Ada] Improve detection of end of the process by GNAT.Expect
authorpmderodat <pmderodat@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 21 Aug 2019 08:31:20 +0000 (08:31 +0000)
committerpmderodat <pmderodat@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 21 Aug 2019 08:31:20 +0000 (08:31 +0000)
'read' system call may be interrupted by signal with 'errno' is set to
EINTER. In this case, re-try a few times.

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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@274791 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ada/ChangeLog
gcc/ada/libgnat/g-expect.adb

index 15fcd261f875c437cfed22b49f9d25aaff81b03f..53ecd1a0ecb8e40e52b682ddffc5151f12af131b 100644 (file)
@@ -1,3 +1,8 @@
+2019-08-21  Vadim Godunko  <godunko@adacore.com>
+
+       * libgnat/g-expect.adb (Expect_Internal): Attempt to read
+       several times when 'read' returns non-positive.
+
 2019-08-21  Piotr Trojanek  <trojanek@adacore.com>
 
        * einfo.adb (Is_Discriminal): Remove extra parens.
index 8601f6bfdd90b487b04cc5bae7adccbf44aaa1da..21c7913840b693760146bda851a5c39e8e0ab622 100644 (file)
@@ -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;