Pull up following revision(s) (requested by hannken in ticket #1698):

sys/kern/sys_pipe.c: revision 1.157

Fix a deadlock where one thread writes to a pipe, has more data
and no space in the pipe and waits on "pipe_wcv" while the reader
is closing the pipe and waits on "pipe_draincv".

Swap the test for "PIPE_EOF" and the "cv_wait_sig()" in "pipe_write()".

PR bin/56422 "zgrep -l sometimes hangs"
This commit is contained in:
martin 2021-10-08 14:59:59 +00:00
parent 790a133b49
commit 4a5c533c1d
1 changed files with 8 additions and 7 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: sys_pipe.c,v 1.140.12.1 2019/05/01 14:51:17 martin Exp $ */
/* $NetBSD: sys_pipe.c,v 1.140.12.2 2021/10/08 14:59:59 martin Exp $ */
/*-
* Copyright (c) 2003, 2007, 2008, 2009 The NetBSD Foundation, Inc.
@ -68,7 +68,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.140.12.1 2019/05/01 14:51:17 martin Exp $");
__KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.140.12.2 2021/10/08 14:59:59 martin Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -1017,11 +1017,6 @@ pipe_write(file_t *fp, off_t *offset, struct uio *uio, kauth_cred_t cred,
break;
}
pipeunlock(wpipe);
error = cv_wait_sig(&wpipe->pipe_wcv, lock);
(void)pipelock(wpipe, false);
if (error != 0)
break;
/*
* If read side wants to go away, we just issue a signal
* to ourselves.
@ -1030,6 +1025,12 @@ pipe_write(file_t *fp, off_t *offset, struct uio *uio, kauth_cred_t cred,
error = EPIPE;
break;
}
pipeunlock(wpipe);
error = cv_wait_sig(&wpipe->pipe_wcv, lock);
(void)pipelock(wpipe, false);
if (error != 0)
break;
wakeup_state = wpipe->pipe_state;
}
}