summaryrefslogtreecommitdiff
path: root/sys/miscfs/fifofs
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2004-05-14 21:33:59 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2004-05-14 21:33:59 +0000
commit8db5f8d29780629a4bf73ec55f434f2c774ec8b2 (patch)
tree5b4896afc89a9caa2d76fa971f348e9e36fd51dd /sys/miscfs/fifofs
parent40415f62a5f614d6d6b0b9a92882934895e42f1a (diff)
Fix a bug that occurs when a FIFO is opened for writing with
O_NONBLOCK set and there are no readers. Before returning ENXIO fifo_open calls VOP_CLOSE (and hence fifo_close). However, since fi_writers has not yet been incremented, when fifo_close decements fi_writers it is one too few. This could cause qmail processes to spin, consuming all the CPU. Noticed by avsm@ and henning@, test case provided by claudio@, Ok pedro@
Diffstat (limited to 'sys/miscfs/fifofs')
-rw-r--r--sys/miscfs/fifofs/fifo_vnops.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/sys/miscfs/fifofs/fifo_vnops.c b/sys/miscfs/fifofs/fifo_vnops.c
index 157f00fd8e9..0ac5f3e37f0 100644
--- a/sys/miscfs/fifofs/fifo_vnops.c
+++ b/sys/miscfs/fifofs/fifo_vnops.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fifo_vnops.c,v 1.19 2004/03/02 04:42:52 tedu Exp $ */
+/* $OpenBSD: fifo_vnops.c,v 1.20 2004/05/14 21:33:58 millert Exp $ */
/* $NetBSD: fifo_vnops.c,v 1.18 1996/03/16 23:52:42 christos Exp $ */
/*
@@ -191,18 +191,20 @@ fifo_open(v)
rso->so_state |= SS_CANTRCVMORE;
}
if (ap->a_mode & FREAD) {
- if (fip->fi_readers++ == 0) {
+ fip->fi_readers++;
+ if (fip->fi_readers == 1) {
fip->fi_writesock->so_state &= ~SS_CANTSENDMORE;
if (fip->fi_writers > 0)
wakeup(&fip->fi_writers);
}
}
if (ap->a_mode & FWRITE) {
+ fip->fi_writers++;
if ((ap->a_mode & O_NONBLOCK) && fip->fi_readers == 0) {
error = ENXIO;
goto bad;
}
- if (fip->fi_writers++ == 0) {
+ if (fip->fi_writers == 1) {
fip->fi_readsock->so_state &= ~SS_CANTRCVMORE;
if (fip->fi_readers > 0)
wakeup(&fip->fi_readers);