From: Alain Spineux Date: Fri, 22 Mar 2024 09:24:26 +0000 (+0100) Subject: BSOCK improve POLL to detect and report errors X-Git-Tag: Release-15.0.3~55 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4b49be52ce62d86820454baff419a1c6d8817e9a;p=thirdparty%2Fbacula.git BSOCK improve POLL to detect and report errors - 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. --- diff --git a/bacula/src/lib/bsys.c b/bacula/src/lib/bsys.c index f7ec1397f..d863b30f9 100644 --- a/bacula/src/lib/bsys.c +++ b/bacula/src/lib/bsys.c @@ -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... */ }