Commit d9a40f22 authored by Scott Vokes's avatar Scott Vokes
Browse files

Audit all uses of poll(2) and check for POLLNVAL.

parent 51e5eccd
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -361,6 +361,11 @@ static bool poll_on_completion(struct bus *b, int fd) {
            uint16_t msec = 0;
            uint8_t read_buf[sizeof(msec)];
            
            if (fds[0].revents & (POLLERR | POLLHUP | POLLNVAL)) {
                BUS_LOG(b, 1, LOG_SENDING_REQUEST, "failed (broken alert pipe)", b->udata);
                return false;
            }

            BUS_LOG(b, 3, LOG_SENDING_REQUEST, "Reading alert pipe...", b->udata);
            ssize_t sz = read(fd, read_buf, sizeof(read_buf));

@@ -370,7 +375,7 @@ static bool poll_on_completion(struct bus *b, int fd) {
                if (msec > 0) {
                    BUS_LOG_SNPRINTF(b, 5, LOG_SENDING_REQUEST, b->udata, 64,
                        " -- awakening client thread with backpressure of %d msec", msec);
                    (void)poll(fds, 0, msec);
                    (void)poll(NULL, 0, msec);
                }

                BUS_LOG(b, 3, LOG_SENDING_REQUEST, "sent!", b->udata);
+2 −2
Original line number Diff line number Diff line
@@ -329,9 +329,9 @@ static void attempt_recv(listener *l, int available) {
        connection_info *ci = l->fd_info[i];
        assert(ci->fd == fd->fd);
        
        if (fd->revents & POLLERR) {
        if (fd->revents & (POLLERR | POLLNVAL)) {
            read_from++;
            BUS_LOG(b, 2, LOG_LISTENER, "pollfd: socket error POLLERR", b->udata);
            BUS_LOG(b, 2, LOG_LISTENER, "pollfd: socket error (POLLERR | POLLNVAL)", b->udata);
            set_error_for_socket(l, i, ci->fd, RX_ERROR_POLLERR);
        } else if (fd->revents & POLLHUP) {
            read_from++;
+2 −2
Original line number Diff line number Diff line
@@ -262,7 +262,7 @@ static bool commit_event_and_block(struct sender *s, tx_info_t *info) {
            short ev = fds[0].revents;
            BUS_LOG_SNPRINTF(b, 8, LOG_SENDER, b->udata, 64,
                "poll: ev %d, errno %d", ev, errno);
            if ((ev & POLLHUP) || (ev & POLLERR) || (ev & POLLNVAL)) {
            if (ev & (POLLHUP | POLLERR | POLLNVAL) {
                /* We've been hung up on due to a shutdown event. */
                close(info->done_pipe);
                return true;
@@ -712,7 +712,7 @@ static void attempt_write(sender *s, int available) {
        BUS_LOG_SNPRINTF(b, 10, LOG_SENDER, b->udata, 64,
            "attempting write on %d (revents 0x%08x)", pfd->fd, pfd->revents);
        
        if (pfd->revents & POLLERR) {
        if (pfd->revents & (POLLERR | POLLNVAL)) {
            written++;
            set_error_for_socket(s, pfd->fd, TX_ERROR_POLLERR);
        } else if (pfd->revents & POLLHUP) {