| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: kern_event.c,v 1.82 2014/09/05 09:20:59 matt Exp $ */ | | 1 | /* $NetBSD: kern_event.c,v 1.83 2015/03/02 19:24:53 christos Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Andrew Doran. | | 8 | * by Andrew Doran. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -48,27 +48,27 @@ | | | @@ -48,27 +48,27 @@ |
48 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | | 48 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
49 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 49 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
50 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 50 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
51 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 51 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
52 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 52 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
53 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 53 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
54 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 54 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
55 | * SUCH DAMAGE. | | 55 | * SUCH DAMAGE. |
56 | * | | 56 | * |
57 | * FreeBSD: src/sys/kern/kern_event.c,v 1.27 2001/07/05 17:10:44 rwatson Exp | | 57 | * FreeBSD: src/sys/kern/kern_event.c,v 1.27 2001/07/05 17:10:44 rwatson Exp |
58 | */ | | 58 | */ |
59 | | | 59 | |
60 | #include <sys/cdefs.h> | | 60 | #include <sys/cdefs.h> |
61 | __KERNEL_RCSID(0, "$NetBSD: kern_event.c,v 1.82 2014/09/05 09:20:59 matt Exp $"); | | 61 | __KERNEL_RCSID(0, "$NetBSD: kern_event.c,v 1.83 2015/03/02 19:24:53 christos Exp $"); |
62 | | | 62 | |
63 | #include <sys/param.h> | | 63 | #include <sys/param.h> |
64 | #include <sys/systm.h> | | 64 | #include <sys/systm.h> |
65 | #include <sys/kernel.h> | | 65 | #include <sys/kernel.h> |
66 | #include <sys/proc.h> | | 66 | #include <sys/proc.h> |
67 | #include <sys/file.h> | | 67 | #include <sys/file.h> |
68 | #include <sys/select.h> | | 68 | #include <sys/select.h> |
69 | #include <sys/queue.h> | | 69 | #include <sys/queue.h> |
70 | #include <sys/event.h> | | 70 | #include <sys/event.h> |
71 | #include <sys/eventvar.h> | | 71 | #include <sys/eventvar.h> |
72 | #include <sys/poll.h> | | 72 | #include <sys/poll.h> |
73 | #include <sys/kmem.h> | | 73 | #include <sys/kmem.h> |
74 | #include <sys/stat.h> | | 74 | #include <sys/stat.h> |
| @@ -538,26 +538,30 @@ filt_proc(struct knote *kn, long hint) | | | @@ -538,26 +538,30 @@ filt_proc(struct knote *kn, long hint) |
538 | struct kevent kev; | | 538 | struct kevent kev; |
539 | struct kqueue *kq; | | 539 | struct kqueue *kq; |
540 | int error; | | 540 | int error; |
541 | | | 541 | |
542 | event = (u_int)hint & NOTE_PCTRLMASK; | | 542 | event = (u_int)hint & NOTE_PCTRLMASK; |
543 | kq = kn->kn_kq; | | 543 | kq = kn->kn_kq; |
544 | fflag = 0; | | 544 | fflag = 0; |
545 | | | 545 | |
546 | /* If the user is interested in this event, record it. */ | | 546 | /* If the user is interested in this event, record it. */ |
547 | if (kn->kn_sfflags & event) | | 547 | if (kn->kn_sfflags & event) |
548 | fflag |= event; | | 548 | fflag |= event; |
549 | | | 549 | |
550 | if (event == NOTE_EXIT) { | | 550 | if (event == NOTE_EXIT) { |
| | | 551 | struct proc *p = kn->kn_obj; |
| | | 552 | |
| | | 553 | if (p != NULL) |
| | | 554 | kn->kn_data = p->p_xstat; |
551 | /* | | 555 | /* |
552 | * Process is gone, so flag the event as finished. | | 556 | * Process is gone, so flag the event as finished. |
553 | * | | 557 | * |
554 | * Detach the knote from watched process and mark | | 558 | * Detach the knote from watched process and mark |
555 | * it as such. We can't leave this to kqueue_scan(), | | 559 | * it as such. We can't leave this to kqueue_scan(), |
556 | * since the process might not exist by then. And we | | 560 | * since the process might not exist by then. And we |
557 | * have to do this now, since psignal KNOTE() is called | | 561 | * have to do this now, since psignal KNOTE() is called |
558 | * also for zombies and we might end up reading freed | | 562 | * also for zombies and we might end up reading freed |
559 | * memory if the kevent would already be picked up | | 563 | * memory if the kevent would already be picked up |
560 | * and knote g/c'ed. | | 564 | * and knote g/c'ed. |
561 | */ | | 565 | */ |
562 | filt_procdetach(kn); | | 566 | filt_procdetach(kn); |
563 | | | 567 | |