diff --git a/ChangeLog b/ChangeLog index 2d4d68e0102..54ea6a44cb6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4777,3 +4777,5 @@ * net/net_poll.c: When readahead data is availalbe, the network poll logic should set POLLIN (or POLLRDNORM), not POLLOUT. Max Holtzberg (2013-5-23) + * fs/fs_poll.c: Actually, it should not ignore invlid descriptors, it + should set the POLLNVAL event and return immediately (2013-5-23). diff --git a/fs/fs_poll.c b/fs/fs_poll.c index 9c5ba39febb..b6a09b64490 100644 --- a/fs/fs_poll.c +++ b/fs/fs_poll.c @@ -163,17 +163,30 @@ static inline int poll_setup(FAR struct pollfd *fds, nfds_t nfds, sem_t *sem) for (i = 0; i < nfds; i++) { - /* Ignore negative descriptors */ + /* Setup the poll descriptor */ - if (fds[i].fd >= 0) + fds[i].sem = sem; + fds[i].priv = NULL; + + /* Check for invalid descriptors */ + + if (fds[i].fd < 0) { - /* Setup the poll descriptor */ + /* Set POLLNVAL to indicate the invalid fd member */ + + fds[i].revents = POLLNVAL; + + /* And increment the semaphore so that poll will return + * immediately (but with a successful return value). + */ + + sem_post(sem); + } + else + { + /* Set up the poll on this valid file descriptor */ - fds[i].sem = sem; fds[i].revents = 0; - fds[i].priv = NULL; - - /* Set up the poll */ ret = poll_fdsetup(fds[i].fd, &fds[i], true); if (ret < 0) @@ -219,18 +232,18 @@ static inline int poll_teardown(FAR struct pollfd *fds, nfds_t nfds, int *count) { ret = status; } - - /* Check if any events were posted */ - - if (fds[i].revents != 0) - { - (*count)++; - } - - /* Un-initialize the poll structure */ - - fds[i].sem = NULL; } + + /* Check if any events were posted */ + + if (fds[i].revents != 0) + { + (*count)++; + } + + /* Un-initialize the poll structure */ + + fds[i].sem = NULL; } return ret;