summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordavidxu <davidxu@FreeBSD.org>2012-07-31 02:00:37 +0000
committerdavidxu <davidxu@FreeBSD.org>2012-07-31 02:00:37 +0000
commitd2b97b91930a11e100e21262dc3c08cb93b7e415 (patch)
tree9bbb35e29abb7acba493b444f512a83ed00f2db0
parentcf6d705d5b2f458f6a07c3c33eac90bca667108a (diff)
downloadFreeBSD-src-d2b97b91930a11e100e21262dc3c08cb93b7e415.zip
FreeBSD-src-d2b97b91930a11e100e21262dc3c08cb93b7e415.tar.gz
When a thread is blocked in direct write state, it only sets PIPE_DIRECTW
flag but not PIPE_WANTW, but FIFO pipe code does not understand this internal state, when a FIFO peer reader closes the pipe, it wants to notify the writer, it checks PIPE_WANTW, if not set, it skips calling wakeup(), so blocked writer never noticed the case, but in general, the writer should return from the syscall with EPIPE error code and may get SIGPIPE signal. Setting the PIPE_WANTW fixed problem, or you can turn off direct write, it should fix the problem too. This bug is found by PR/170203. Another bug in FIFO pipe code is when peer closes the pipe, another end which is being blocked in select() or poll() is not notified, it missed to call pipeselwakeup(). Third problem is found in poll regression test, the existing code can not pass 6b,6c,6d tests, but FreeBSD-4 works. This commit does not fix the problem, I still need to study more to find the cause. PR: 170203 Tested by: Garrett Copper &lt; yanegomi at gmail dot com &gt;
-rw-r--r--sys/fs/fifofs/fifo_vnops.c10
-rw-r--r--sys/kern/sys_pipe.c6
-rw-r--r--sys/sys/pipe.h2
3 files changed, 12 insertions, 6 deletions
diff --git a/sys/fs/fifofs/fifo_vnops.c b/sys/fs/fifofs/fifo_vnops.c
index 0b065a6..859f68c 100644
--- a/sys/fs/fifofs/fifo_vnops.c
+++ b/sys/fs/fifofs/fifo_vnops.c
@@ -283,8 +283,11 @@ fifo_close(ap)
if (fip->fi_readers == 0) {
PIPE_LOCK(cpipe);
cpipe->pipe_state |= PIPE_EOF;
- if (cpipe->pipe_state & PIPE_WANTW)
+ if ((cpipe->pipe_state & PIPE_WANTW)) {
+ cpipe->pipe_state &= ~PIPE_WANTW;
wakeup(cpipe);
+ }
+ pipeselwakeup(cpipe);
PIPE_UNLOCK(cpipe);
}
}
@@ -293,10 +296,13 @@ fifo_close(ap)
if (fip->fi_writers == 0) {
PIPE_LOCK(cpipe);
cpipe->pipe_state |= PIPE_EOF;
- if (cpipe->pipe_state & PIPE_WANTR)
+ if ((cpipe->pipe_state & PIPE_WANTR)) {
+ cpipe->pipe_state &= ~PIPE_WANTR;
wakeup(cpipe);
+ }
fip->fi_wgen++;
FIFO_UPDWGEN(fip, cpipe);
+ pipeselwakeup(cpipe);
PIPE_UNLOCK(cpipe);
}
}
diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c
index 43c39fc..02664e9 100644
--- a/sys/kern/sys_pipe.c
+++ b/sys/kern/sys_pipe.c
@@ -227,7 +227,6 @@ static int pipe_create(struct pipe *pipe, int backing);
static int pipe_paircreate(struct thread *td, struct pipepair **p_pp);
static __inline int pipelock(struct pipe *cpipe, int catch);
static __inline void pipeunlock(struct pipe *cpipe);
-static __inline void pipeselwakeup(struct pipe *cpipe);
#ifndef PIPE_NODIRECT
static int pipe_build_write_buffer(struct pipe *wpipe, struct uio *uio);
static void pipe_destroy_write_buffer(struct pipe *wpipe);
@@ -607,7 +606,7 @@ pipeunlock(cpipe)
}
}
-static __inline void
+void
pipeselwakeup(cpipe)
struct pipe *cpipe;
{
@@ -738,7 +737,7 @@ pipe_read(fp, uio, active_cred, flags, td)
rpipe->pipe_map.pos += size;
rpipe->pipe_map.cnt -= size;
if (rpipe->pipe_map.cnt == 0) {
- rpipe->pipe_state &= ~PIPE_DIRECTW;
+ rpipe->pipe_state &= ~(PIPE_DIRECTW|PIPE_WANTW);
wakeup(rpipe);
}
#endif
@@ -1001,6 +1000,7 @@ retry:
wakeup(wpipe);
}
pipeselwakeup(wpipe);
+ wpipe->pipe_state |= PIPE_WANTW;
pipeunlock(wpipe);
error = msleep(wpipe, PIPE_MTX(wpipe), PRIBIO | PCATCH,
"pipdwt", 0);
diff --git a/sys/sys/pipe.h b/sys/sys/pipe.h
index d60185a..f0029a8 100644
--- a/sys/sys/pipe.h
+++ b/sys/sys/pipe.h
@@ -143,5 +143,5 @@ struct pipepair {
void pipe_dtor(struct pipe *dpipe);
int pipe_named_ctor(struct pipe **ppipe, struct thread *td);
-
+void pipeselwakeup(struct pipe *cpipe);
#endif /* !_SYS_PIPE_H_ */
OpenPOWER on IntegriCloud