]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
vgdb: Handle EAGAIN in read_buf
authorMark Wielaard <mark@klomp.org>
Thu, 20 Apr 2023 10:59:02 +0000 (12:59 +0200)
committerMark Wielaard <mark@klomp.org>
Thu, 20 Apr 2023 11:00:49 +0000 (13:00 +0200)
The file descriptor is on non-blocking mode and read_buf should only
be called when poll gave us an POLLIN event signaling the file
descriptor is ready for reading from. Still sometimes we do get an
occasional EAGAIN. Just do as told in that case and try to read again.

Also fix an ERROR errno in getpkt. This has never been observed, but
not getting the actual errno if the write fails in that case would be
really confusing.

coregrind/vgdb.c

index 7ed9a8b2e902a2d8a4b2a2bb85f81e7b7f275649..ca673e368d3add04bf7cfbd56b95ebf5bea14a40 100644 (file)
@@ -398,7 +398,14 @@ int read_buf(int fd, char* buf, const char* desc)
 {
    int nrread;
    DEBUG(2, "reading %s\n", desc);
-   nrread = read(fd, buf, PBUFSIZ);
+   /* The file descriptor is on non-blocking mode and read_buf should only
+      be called when poll gave us an POLLIN event signaling the file
+      descriptor is ready for reading from. Still sometimes we do get an
+      occasional EAGAIN. Just do as told in that case and try to read
+      again.  */
+   do {
+      nrread = read(fd, buf, PBUFSIZ);
+   } while (nrread == -1 && errno == EAGAIN);
    if (nrread == -1) {
       ERROR(errno, "error reading %s\n", desc);
       return -1;
@@ -708,7 +715,7 @@ getpkt(char *buf, int fromfd, int ackfd)
      TSFPRINTF(stderr, "Bad checksum, sentsum=0x%x, csum=0x%x, buf=%s\n",
                (c1 << 4) + c2, csum, buf);
      if (write(ackfd, "-", 1) != 1)
-        ERROR(0, "error when writing - (nack)\n");
+        ERROR(errno, "error when writing - (nack)\n");
      else
         add_written(1);
   }