]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
BSOCK improve POLL to detect and report errors
authorAlain Spineux <alain@baculasystems.com>
Fri, 22 Mar 2024 09:24:26 +0000 (10:24 +0100)
committerEric Bollengier <eric@baculasystems.com>
Wed, 4 Dec 2024 08:14:25 +0000 (09:14 +0100)
- when I was crashing my SD during my dedup2 tests,
  the FD was oftent stuck with thread using 100% cpu.
  This patch solved the problem, now the FD just terminate
  the job.

bacula/src/lib/bsys.c

index f7ec1397ffd9326208ddba63293240fc231b3edd..d863b30f9884d4733a33e13255c0422bedd16e0b 100644 (file)
@@ -1489,9 +1489,24 @@ int fd_wait_data(int fd, fd_wait_mode mode, int sec, int msec)
       return -1;
 
    default:
+      /* POLLNVAL, POLLERR & POLLHUP are inevitable in "revents" and must be handled */
+      if (fds[0].revents & POLLNVAL) {
+         return -1; // the FD is not open
+      }
+      if (fds[0].revents & POLLERR) {
+         return -1; // something wrong, can also warn you about SIGPIPE if you try to write into a closed pipe
+      }
+      if (fds[0].revents & POLLHUP) {
+         /* The peer as closed the connection */
+         if (mode == WAIT_READ) {
+            /* lets read the last bytes until the EOF (read = 0 bytes) */
+         } else {
+            /* trying to write into a closed socket or pipe ? */
+            return -1; // maybe this error was already handled by POLLERR above
+         }
+      }
       if (fds[0].revents & POLLIN || fds[0].revents & POLLOUT) {
          return 1;
-
       } else {
          return -1;             /* unexpected... */
       }