Revert of: commit 730d22dbca18c6488ee11d40c1456ce5722191fc Author: mlelstv Date: Fri Apr 26 17:24:23 2019 +0000 Handle half-closed pipes in FIONWRITE and FIONSPACE. commit c07acfde1776881558ea5c9de165a136d7f03eb1 Author: mlelstv Date: Fri Apr 26 17:20:49 2019 +0000 Clean up pipe structure before recycling it. Index: sys_pipe.c =================================================================== RCS file: /cvsroot/src/sys/kern/sys_pipe.c,v retrieving revision 1.148 diff -u -r1.148 sys_pipe.c --- sys_pipe.c 26 Apr 2019 17:24:23 -0000 1.148 +++ sys_pipe.c 6 May 2020 10:09:00 -0000 @@ -1,4 +1,4 @@ -/* $NetBSD: sys_pipe.c,v 1.148 2019/04/26 17:24:23 mlelstv Exp $ */ +/* $NetBSD: sys_pipe.c,v 1.147 2019/04/26 17:20:49 mlelstv Exp $ */ /*- * Copyright (c) 2003, 2007, 2008, 2009 The NetBSD Foundation, Inc. @@ -68,7 +68,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.148 2019/04/26 17:24:23 mlelstv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.147 2019/04/26 17:20:49 mlelstv Exp $"); #include #include @@ -1096,12 +1096,10 @@ case FIONWRITE: /* Look at other side */ - mutex_enter(lock); pipe = pipe->pipe_peer; - if (pipe == NULL) - *(int *)data = 0; + mutex_enter(lock); #ifndef PIPE_NODIRECT - else if (pipe->pipe_state & PIPE_DIRECTW) + if (pipe->pipe_state & PIPE_DIRECTW) *(int *)data = pipe->pipe_map.cnt; else #endif @@ -1111,11 +1109,8 @@ case FIONSPACE: /* Look at other side */ - mutex_enter(lock); pipe = pipe->pipe_peer; - if (pipe == NULL) - *(int *)data = 0; - else + mutex_enter(lock); #ifndef PIPE_NODIRECT /* * If we're in direct-mode, we don't really have a @@ -1336,8 +1331,6 @@ free_resources: pipe->pipe_pgid = 0; pipe->pipe_state = PIPE_SIGNALR; - pipe->pipe_peer = NULL; - pipe->pipe_lock = NULL; pipe_free_kmem(pipe); if (pipe->pipe_kmem != 0) { pool_cache_put(pipe_rd_cache, pipe);