From: Matthew Dillon Date: Sun, 16 Aug 2009 03:56:04 +0000 (-0700) Subject: PIPE - Fix a blocking race. X-Git-Url: https://gitweb.dragonflybsd.org/~polachok/dragonfly.git/commitdiff_plain/958de3056ed7f8ed4e39ff27855adf89b5d6cd0e PIPE - Fix a blocking race. * A pipe can get stuck in "pipewr" due to a race caused by a selwakeup() before a tsleep(). Fix the race. --- diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c index 97a219e402..bf24ac257f 100644 --- a/sys/kern/sys_pipe.c +++ b/sys/kern/sys_pipe.c @@ -871,10 +871,11 @@ pipe_write(struct file *fp, struct uio *uio, struct ucred *cred, int fflags) * wake up select/poll. */ if (space == 0) { - pipeselwakeup(wpipe); - ++wpipe->pipe_wantwcnt; wpipe->pipe_state |= PIPE_WANTW; - error = tsleep(wpipe, PCATCH, "pipewr", 0); + ++wpipe->pipe_wantwcnt; + pipeselwakeup(wpipe); + if (wpipe->pipe_state & PIPE_WANTW) + error = tsleep(wpipe, PCATCH, "pipewr", 0); ++pipe_wblocked_count; } lwkt_reltoken(&rlock);