[Ada] GNAT.Expect (Expect_Internal): Try to call 'poll' few times
authorVadim Godunko <godunko@adacore.com>
Tue, 17 Sep 2019 08:01:42 +0000 (08:01 +0000)
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>
Tue, 17 Sep 2019 08:01:42 +0000 (08:01 +0000)
'poll' returns -1 in case of any error (including interruption by a
signal), so call need to be repeated few times to avoid false failures.

2019-09-17  Vadim Godunko  <godunko@adacore.com>

gcc/ada/

* libgnat/g-expect.adb (Expect_Internal): Try to call 'poll' few
times.

From-SVN: r275782

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

index c952898352fac1bd2a13d97b197d18bdab307470..ab8c8a52226f858621c3d52f56ab26a0617ce354 100644 (file)
@@ -1,3 +1,8 @@
+2019-09-17  Vadim Godunko  <godunko@adacore.com>
+
+       * libgnat/g-expect.adb (Expect_Internal): Try to call 'poll' few
+       times.
+
 2019-09-17  Vadim Godunko  <godunko@adacore.com>
 
        * libgnat/g-expect.ads, libgnat/g-expect.adb (Close_Input): New
index b44c7a5f016691ec1250655cc0815c8bc7cc8ccb..0ee010e4cfbea02f42b7ab8d281a84b31c26506d 100644 (file)
@@ -679,8 +679,17 @@ package body GNAT.Expect is
          --  Loop until we match or we have a timeout
 
          loop
-            Num_Descriptors :=
-              Poll (Fds'Address, Fds_Count, Timeout, D'Access, Is_Set'Address);
+            --  Poll 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 call Poll a few times.
+
+            for J in 1 .. 3 loop
+               Num_Descriptors :=
+                 Poll
+                   (Fds'Address, Fds_Count, Timeout, D'Access, Is_Set'Address);
+
+               exit when Num_Descriptors /= -1;
+            end loop;
 
             case Num_Descriptors is