summaryrefslogtreecommitdiffstats
path: root/sys/kern/sys_pipe.c
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 /sys/kern/sys_pipe.c
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;
Diffstat (limited to 'sys/kern/sys_pipe.c')
-rw-r--r--sys/kern/sys_pipe.c6
1 files changed, 3 insertions, 3 deletions
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);
OpenPOWER on IntegriCloud