Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Add support for unblocking read/write when close called.
details: https://anonhg.NetBSD.org/src/rev/fd01c0c24814
branches: trunk
changeset: 749917:fd01c0c24814
user: dsl <dsl%NetBSD.org@localhost>
date: Sat Dec 12 21:28:04 2009 +0000
description:
Add support for unblocking read/write when close called.
Fixes PR/26567 for pipes.
(NB ad backed out the fix for sockets)
diffstat:
sys/kern/sys_pipe.c | 33 +++++++++++++++++++++++++++++----
sys/sys/pipe.h | 3 ++-
2 files changed, 31 insertions(+), 5 deletions(-)
diffs (100 lines):
diff -r a039413eeae4 -r fd01c0c24814 sys/kern/sys_pipe.c
--- a/sys/kern/sys_pipe.c Sat Dec 12 17:48:54 2009 +0000
+++ b/sys/kern/sys_pipe.c Sat Dec 12 21:28:04 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sys_pipe.c,v 1.122 2009/12/10 20:55:17 dsl Exp $ */
+/* $NetBSD: sys_pipe.c,v 1.123 2009/12/12 21:28:04 dsl 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.122 2009/12/10 20:55:17 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_pipe.c,v 1.123 2009/12/12 21:28:04 dsl Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -109,6 +109,7 @@
static int pipe_kqfilter(file_t *, struct knote *);
static int pipe_stat(file_t *, struct stat *);
static int pipe_ioctl(file_t *, u_long, void *);
+static void pipe_abort(file_t *);
static const struct fileops pipeops = {
.fo_read = pipe_read,
@@ -119,7 +120,7 @@
.fo_stat = pipe_stat,
.fo_close = pipe_close,
.fo_kqfilter = pipe_kqfilter,
- .fo_abort = fnullop_abort,
+ .fo_abort = pipe_abort,
};
/*
@@ -541,8 +542,12 @@
* Detect EOF condition.
* Read returns 0 on EOF, no need to set error.
*/
- if (rpipe->pipe_state & PIPE_EOF)
+ if (rpipe->pipe_state & (PIPE_EOF | PIPE_ABORTED)) {
+ if (rpipe->pipe_state & PIPE_ABORTED)
+ /* Another thread has called close() */
+ error = EBADF;
break;
+ }
/*
* Don't block on non-blocking I/O.
@@ -979,6 +984,13 @@
break;
}
+ if (wpipe->pipe_state & PIPE_ABORTED) {
+ /* Another thread has called close() */
+ if (uio->uio_resid == 0)
+ error = EBADF;
+ break;
+ }
+
/*
* We have no more space and have something to offer,
* wake up select/poll.
@@ -1204,6 +1216,19 @@
}
static void
+pipe_abort(file_t *fp)
+{
+ struct pipe *pipe = fp->f_data;
+
+ /* Unblock blocked reads/writes - they will return EBADF. */
+ mutex_enter(pipe->pipe_lock);
+ pipe->pipe_state |= PIPE_ABORTED;
+ cv_broadcast(&pipe->pipe_rcv);
+ cv_broadcast(&pipe->pipe_wcv);
+ mutex_exit(pipe->pipe_lock);
+}
+
+static void
pipe_free_kmem(struct pipe *pipe)
{
diff -r a039413eeae4 -r fd01c0c24814 sys/sys/pipe.h
--- a/sys/sys/pipe.h Sat Dec 12 17:48:54 2009 +0000
+++ b/sys/sys/pipe.h Sat Dec 12 21:28:04 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pipe.h,v 1.29 2009/11/26 16:18:37 pooka Exp $ */
+/* $NetBSD: pipe.h,v 1.30 2009/12/12 21:28:04 dsl Exp $ */
/*
* Copyright (c) 1996 John S. Dyson
@@ -96,6 +96,7 @@
pointers/data. */
#define PIPE_LWANT 0x200 /* Process wants exclusive access to
pointers/data. */
+#define PIPE_ABORTED 0x400 /* fo_abort()ed, unblock read/write */
/*
* Per-pipe data structure.
Home |
Main Index |
Thread Index |
Old Index