diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2013-05-23 07:48:32 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2013-05-23 07:48:32 -0600 |
commit | d691706b0c0fb7c2b8eeccf6f07f09fd0ecbe3fe (patch) | |
tree | e5a3c55a28014aa64b0604ae08248f201e5c0ec9 /nuttx/fs | |
parent | 26b10bd86f5d58fe9df3af58d5dd65f2542312fe (diff) | |
download | px4-nuttx-d691706b0c0fb7c2b8eeccf6f07f09fd0ecbe3fe.tar.gz px4-nuttx-d691706b0c0fb7c2b8eeccf6f07f09fd0ecbe3fe.tar.bz2 px4-nuttx-d691706b0c0fb7c2b8eeccf6f07f09fd0ecbe3fe.zip |
poll needs to set POLLNVAL if file descriptor is bad
Diffstat (limited to 'nuttx/fs')
-rw-r--r-- | nuttx/fs/fs_poll.c | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/nuttx/fs/fs_poll.c b/nuttx/fs/fs_poll.c index 9c5ba39fe..b6a09b644 100644 --- a/nuttx/fs/fs_poll.c +++ b/nuttx/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].sem = sem; - fds[i].revents = 0; - fds[i].priv = NULL; + 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 */ - /* Set up the poll */ + fds[i].revents = 0; 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 */ + /* Check if any events were posted */ - if (fds[i].revents != 0) - { - (*count)++; - } + if (fds[i].revents != 0) + { + (*count)++; + } - /* Un-initialize the poll structure */ + /* Un-initialize the poll structure */ - fds[i].sem = NULL; - } + fds[i].sem = NULL; } return ret; |