From b4c74bf206e5864dbbff8a1c6d59d1ce9893752d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 23 May 2013 15:41:15 -0600 Subject: poll again; if fd is less than zero, it should set revents to zero, not POLLNVAL --- nuttx/ChangeLog | 3 +-- nuttx/fs/fs_poll.c | 26 ++++++++++---------------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index e33660231..ba34d1201 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -4777,8 +4777,7 @@ * 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). + * fs/fs_poll.c: Actually, it should also set revents == 0. (2013-5-23). * libc/misc/lib_slcdencode.c and lib_slcddecode.c: Add logic to marshal and serialized special SLCD intermixed with normal ASCII data (2013-5-23) * configs/stm32ldiscovery/src/stm32_lcd.c: STM32L-Discovery's segment LCD diff --git a/nuttx/fs/fs_poll.c b/nuttx/fs/fs_poll.c index b6a09b644..52d7f94a8 100644 --- a/nuttx/fs/fs_poll.c +++ b/nuttx/fs/fs_poll.c @@ -166,28 +166,22 @@ static inline int poll_setup(FAR struct pollfd *fds, nfds_t nfds, sem_t *sem) /* Setup the poll descriptor */ fds[i].sem = sem; + fds[i].revents = 0; fds[i].priv = NULL; - /* Check for invalid descriptors */ - - if (fds[i].fd < 0) - { - /* 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). - */ + /* Check for invalid descriptors. "If the value of fd is less than 0, + * events shall be ignored, and revents shall be set to 0 in that entry + * on return from poll()." + * + * NOTE: There is a potential problem here. If there is only one fd + * and if it is negative, then poll will hang. From my reading of the + * spec, that appears to be the correct behavior. + */ - sem_post(sem); - } - else + if (fds[i].fd >= 0) { /* Set up the poll on this valid file descriptor */ - fds[i].revents = 0; - ret = poll_fdsetup(fds[i].fd, &fds[i], true); if (ret < 0) { -- cgit v1.2.3