Source-Changes-HG archive

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

[src/trunk]: src/sys/kern Don't add kevents to closing file descriptors (from...



details:   https://anonhg.NetBSD.org/src/rev/2fe6345f9f61
branches:  trunk
changeset: 827740:2fe6345f9f61
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Nov 11 03:58:01 2017 +0000

description:
Don't add kevents to closing file descriptors (from riastradh)

diffstat:

 sys/kern/kern_event.c |  12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diffs (47 lines):

diff -r 405692b4e847 -r 2fe6345f9f61 sys/kern/kern_event.c
--- a/sys/kern/kern_event.c     Fri Nov 10 22:54:20 2017 +0000
+++ b/sys/kern/kern_event.c     Sat Nov 11 03:58:01 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_event.c,v 1.97 2017/11/07 18:35:57 christos Exp $ */
+/*     $NetBSD: kern_event.c,v 1.98 2017/11/11 03:58:01 christos Exp $ */
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -58,7 +58,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_event.c,v 1.97 2017/11/07 18:35:57 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_event.c,v 1.98 2017/11/11 03:58:01 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -982,6 +982,10 @@
                }
                mutex_enter(&fdp->fd_lock);
                ff = fdp->fd_dt->dt_ff[fd];
+               if (ff->ff_refcnt & FR_CLOSING) {
+                       error = EBADF;
+                       goto doneunlock;
+               }
                if (fd <= fdp->fd_lastkqfile) {
                        SLIST_FOREACH(kn, &ff->ff_knlist, kn_link) {
                                if (kq == kn->kn_kq &&
@@ -1096,8 +1100,7 @@
        } else {
                if (kn == NULL) {
                        error = ENOENT;
-                       mutex_exit(&fdp->fd_lock);
-                       goto done;
+                       goto doneunlock;
                }
                if (kev->flags & EV_DELETE) {
                        /* knote_detach() drops fdp->fd_lock */
@@ -1118,6 +1121,7 @@
        if ((kev->flags & EV_ENABLE)) {
                knote_enqueue(kn);
        }
+doneunlock:
        mutex_exit(&fdp->fd_lock);
  done:
        rw_exit(&kqueue_filter_lock);



Home | Main Index | Thread Index | Old Index