From 027a4461589d328ec2d81f23bcda8a60559aa893 Mon Sep 17 00:00:00 2001 From: Jussi Kivilinna Date: Thu, 3 Aug 2017 09:58:20 -0600 Subject: [PATCH] poll: fix poll for regular files and block devices. Open Group documentation tells that poll (and select) support regular files and that 'Regular files shall always poll TRUE for reading and writing'. --- fs/vfs/fs_poll.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/fs/vfs/fs_poll.c b/fs/vfs/fs_poll.c index b850ef217a..13b82635bc 100644 --- a/fs/vfs/fs_poll.c +++ b/fs/vfs/fs_poll.c @@ -272,15 +272,38 @@ int file_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup) DEBUGASSERT(filep != NULL && filep->f_inode != NULL); inode = filep->f_inode; - /* Is a driver registered? Does it support the poll method? - * If not, return -ENOSYS - */ - - if (inode != NULL && inode->u.i_ops != NULL && inode->u.i_ops->poll != NULL) + if (inode != NULL) { - /* Yes, it does... Setup the poll */ + /* Is a driver registered? Does it support the poll method? + * If not, return -ENOSYS + */ - ret = (int)inode->u.i_ops->poll(filep, fds, setup); + if (INODE_IS_DRIVER(inode) && + inode->u.i_ops != NULL && inode->u.i_ops->poll != NULL) + { + /* Yes, it does... Setup the poll */ + + ret = (int)inode->u.i_ops->poll(filep, fds, setup); + } + + /* Regular files (and block devices) are always readable and + * writable. Open Group: "Regular files shall always poll TRUE for + * reading and writing." + */ + + if (INODE_IS_MOUNTPT(inode) || INODE_IS_BLOCK(inode)) + { + if (setup) + { + fds->revents |= (fds->events & (POLLIN | POLLOUT)); + if (fds->revents != 0) + { + sem_post(fds->sem); + } + } + + ret = OK; + } } return ret;