From 6dd84b0bdcb72ff675a1be4a710f1624b765d827 Mon Sep 17 00:00:00 2001 From: Robert Watson Date: Mon, 12 Sep 2005 10:16:18 +0000 Subject: [PATCH] Only poll the fifo for read events if the fifo is attached to a readable file descriptor. Otherwise, the read end of a fifo might return that it is writable (which it isn't). Only poll the fifo for write events if the fifo attached to a writable file descriptor. Otherwise, the write end of a fifo might return that it is readable (which it isn't). In the event that a file is FREAD|FWRITE (which is allowed by POSIX, but has undefined behavior), we poll for both. MFC after: 3 days --- sys/fs/fifofs/fifo_vnops.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/fs/fifofs/fifo_vnops.c b/sys/fs/fifofs/fifo_vnops.c index 4483fdf941a4..f355d5afdf4a 100644 --- a/sys/fs/fifofs/fifo_vnops.c +++ b/sys/fs/fifofs/fifo_vnops.c @@ -615,7 +615,7 @@ fifo_poll_f(struct file *fp, int events, struct ucred *cred, struct thread *td) fip = fp->f_data; levents = events & (POLLIN | POLLINIGNEOF | POLLPRI | POLLRDNORM | POLLRDBAND); - if (levents) { + if ((fp->f_flag & FREAD) && levents) { /* * If POLLIN or POLLRDNORM is requested and POLLINIGNEOF is * not, then convert the first two to the last one. This @@ -641,7 +641,7 @@ fifo_poll_f(struct file *fp, int events, struct ucred *cred, struct thread *td) } } levents = events & (POLLOUT | POLLWRNORM | POLLWRBAND); - if (levents) { + if ((fp->f_flag & FWRITE) && levents) { filetmp.f_data = fip->fi_writesock; filetmp.f_cred = cred; if (filetmp.f_data) {