Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Handle half-closed pipes in FIONWRITE and FIONSPACE.



details:   https://anonhg.NetBSD.org/src/rev/48fdde82a84c
branches:  trunk
changeset: 450816:48fdde82a84c
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Fri Apr 26 17:24:23 2019 +0000

description:
Handle half-closed pipes in FIONWRITE and FIONSPACE.

diffstat:

 sys/kern/sys_pipe.c |  15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)

diffs (46 lines):

diff -r db10d7d2b1b7 -r 48fdde82a84c sys/kern/sys_pipe.c
--- a/sys/kern/sys_pipe.c       Fri Apr 26 17:20:49 2019 +0000
+++ b/sys/kern/sys_pipe.c       Fri Apr 26 17:24:23 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sys_pipe.c,v 1.147 2019/04/26 17:20:49 mlelstv Exp $   */
+/*     $NetBSD: sys_pipe.c,v 1.148 2019/04/26 17:24:23 mlelstv 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.147 2019/04/26 17:20:49 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.148 2019/04/26 17:24:23 mlelstv Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1096,10 +1096,12 @@
 
        case FIONWRITE:
                /* Look at other side */
+               mutex_enter(lock);
                pipe = pipe->pipe_peer;
-               mutex_enter(lock);
+               if (pipe == NULL)
+                       *(int *)data = 0;
 #ifndef PIPE_NODIRECT
-               if (pipe->pipe_state & PIPE_DIRECTW)
+               else if (pipe->pipe_state & PIPE_DIRECTW)
                        *(int *)data = pipe->pipe_map.cnt;
                else
 #endif
@@ -1109,8 +1111,11 @@
 
        case FIONSPACE:
                /* Look at other side */
+               mutex_enter(lock);
                pipe = pipe->pipe_peer;
-               mutex_enter(lock);
+               if (pipe == NULL)
+                       *(int *)data = 0;
+               else
 #ifndef PIPE_NODIRECT
                /*
                 * If we're in direct-mode, we don't really have a



Home | Main Index | Thread Index | Old Index