diff options
author | Sebastien Marie <semarie@cvs.openbsd.org> | 2019-07-13 06:52:00 +0000 |
---|---|---|
committer | Sebastien Marie <semarie@cvs.openbsd.org> | 2019-07-13 06:52:00 +0000 |
commit | b28d1d4917efbd28b9c45b7726a545ddc6df8908 (patch) | |
tree | cbe911d4499d2da03c438768e8c1dcd8f62fbba1 /sys/kern | |
parent | d2b8b80d8d1513228cf6dbf8120b40f84781da69 (diff) |
pipe_write() do opportunistic buffer resizing, when the buffer is empty.
but there is a possible sleeping point between the check (cnt == 0) and
the resize (pipespace() call), resulting resizing on possibly not empty
buffer.
fix it by rechecking the buffer usage once the exclusive lock is hold.
it should be revisited later as part of larger work on pipe(2).
ok visa@ anton@
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/sys_pipe.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c index 57d8ad74530..1df0c0e4dd3 100644 --- a/sys/kern/sys_pipe.c +++ b/sys/kern/sys_pipe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sys_pipe.c,v 1.90 2019/07/09 15:02:15 semarie Exp $ */ +/* $OpenBSD: sys_pipe.c,v 1.91 2019/07/13 06:51:59 semarie Exp $ */ /* * Copyright (c) 1996 John S. Dyson @@ -460,7 +460,8 @@ pipe_write(struct file *fp, struct uio *uio, int fflags) npipe = atomic_inc_int_nv(&nbigpipe); if ((npipe <= LIMITBIGPIPES) && (error = pipelock(wpipe)) == 0) { - if (pipespace(wpipe, BIG_PIPE_SIZE) != 0) + if ((wpipe->pipe_buffer.cnt != 0) || + (pipespace(wpipe, BIG_PIPE_SIZE) != 0)) atomic_dec_int(&nbigpipe); pipeunlock(wpipe); } else |