Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 641275e1 authored by Haynes Mathew George's avatar Haynes Mathew George Committed by Eric Laurent
Browse files

sndmonitor: treat errors during poll

Bug: 30075678
Change-Id: I5e17c1def67b5c71461b43bee83a06e2126e29bb
parent 8721b4df
Loading
Loading
Loading
Loading
+28 −1
Original line number Diff line number Diff line
@@ -430,9 +430,20 @@ void * monitor_thread_loop(void * args __unused)

    while (1) {
        if (poll(pfd, num_poll_fds, -1) < 0) {
            int errno_ = errno;
            ALOGE("poll() failed w/ err %s", strerror(errno));
            switch (errno_) {
            case EINTR:
            case ENOMEM:
                sleep(2);
                continue;
            default:
                /* above errors can be caused due to current system
                   state .. any other error is not expected */
                LOG_ALWAYS_FATAL("unxpected poll() system call failure");
                break;
            }
        }
        ALOGV("out of poll()");

#define READY_TO_READ(p) ((p)->revents & (POLLIN|POLLPRI))
@@ -446,6 +457,11 @@ void * monitor_thread_loop(void * args __unused)
                break;
        } else if (ERROR_IN_FD(&pfd[0])) {
            // do not consider for poll again
            // POLLERR - can this happen?
            // POLLHUP - adev must not close pipe
            // POLLNVAL - fd is valid
            LOG_ALWAYS_FATAL("unxpected error in pipe poll fd 0x%x",
                             pfd[0].revents);
            pfd[0].fd *= -1;
        }

@@ -456,6 +472,11 @@ void * monitor_thread_loop(void * args __unused)
                on_sndcard_state_update(s);
            else if (ERROR_IN_FD(&pfd[i])) {
                // do not consider for poll again
                // POLLERR - can this happen as we are reading from a fs?
                // POLLHUP - not valid for cardN/state
                // POLLNVAL - fd is valid
                LOG_ALWAYS_FATAL("unxpected error in card poll fd 0x%x",
                                 pfd[i].revents);
                pfd[i].fd *= -1;
            }
            ++i;
@@ -467,11 +488,17 @@ void * monitor_thread_loop(void * args __unused)
                on_dev_event(d);
            else if (ERROR_IN_FD(&pfd[i])) {
                // do not consider for poll again
                // POLLERR - can this happen as we are reading from a fs?
                // POLLHUP - not valid for switch/state
                // POLLNVAL - fd is valid
                LOG_ALWAYS_FATAL("unxpected error in dev poll fd 0x%x",
                                 pfd[i].revents);
                pfd[i].fd *= -1;
            }
            ++i;
        }
    }

    return NULL;
}