kern_event.c (50d3286d9dbd7bec7aef9c7ac76eaa690a760bec) kern_event.c (ed5848c835a4444c2ec2a0f6c6a33071413a81c3)
1/*-
2 * Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org>
3 * Copyright 2004 John-Mark Gurney <jmg@FreeBSD.org>
4 * Copyright (c) 2009 Apple, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 841 unchanged lines hidden (view full) ---

850{
851 struct kevent keva[KQ_NEVENTS];
852 struct kevent *kevp, *changes;
853 struct kqueue *kq;
854 struct file *fp;
855 cap_rights_t rights;
856 int i, n, nerrors, error;
857
1/*-
2 * Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org>
3 * Copyright 2004 John-Mark Gurney <jmg@FreeBSD.org>
4 * Copyright (c) 2009 Apple, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 841 unchanged lines hidden (view full) ---

850{
851 struct kevent keva[KQ_NEVENTS];
852 struct kevent *kevp, *changes;
853 struct kqueue *kq;
854 struct file *fp;
855 cap_rights_t rights;
856 int i, n, nerrors, error;
857
858 error = fget(td, fd, cap_rights_init(&rights, CAP_POST_EVENT), &fp);
858 cap_rights_init(&rights);
859 if (nchanges > 0)
860 cap_rights_set(&rights, CAP_KQUEUE_CHANGE);
861 if (nevents > 0)
862 cap_rights_set(&rights, CAP_KQUEUE_EVENT);
863 error = fget(td, fd, &rights, &fp);
859 if (error != 0)
860 return (error);
864 if (error != 0)
865 return (error);
861 if ((error = kqueue_acquire(fp, &kq)) != 0)
866
867 error = kqueue_acquire(fp, &kq);
868 if (error != 0)
862 goto done_norel;
863
864 nerrors = 0;
865
866 while (nchanges > 0) {
867 n = nchanges > KQ_NEVENTS ? KQ_NEVENTS : nchanges;
868 error = k_ops->k_copyin(k_ops->arg, keva, n);
869 if (error)

--- 140 unchanged lines hidden (view full) ---

1010 return EINVAL;
1011
1012 tkn = knote_alloc(waitok); /* prevent waiting with locks */
1013
1014findkn:
1015 if (fops->f_isfd) {
1016 KASSERT(td != NULL, ("td is NULL"));
1017 error = fget(td, kev->ident,
869 goto done_norel;
870
871 nerrors = 0;
872
873 while (nchanges > 0) {
874 n = nchanges > KQ_NEVENTS ? KQ_NEVENTS : nchanges;
875 error = k_ops->k_copyin(k_ops->arg, keva, n);
876 if (error)

--- 140 unchanged lines hidden (view full) ---

1017 return EINVAL;
1018
1019 tkn = knote_alloc(waitok); /* prevent waiting with locks */
1020
1021findkn:
1022 if (fops->f_isfd) {
1023 KASSERT(td != NULL, ("td is NULL"));
1024 error = fget(td, kev->ident,
1018 cap_rights_init(&rights, CAP_POLL_EVENT), &fp);
1025 cap_rights_init(&rights, CAP_EVENT), &fp);
1019 if (error)
1020 goto done;
1021
1022 if ((kev->flags & EV_ADD) == EV_ADD && kqueue_expand(kq, fops,
1023 kev->ident, 0) != 0) {
1024 /* try again */
1025 fdrop(fp, td);
1026 fp = NULL;

--- 1269 unchanged lines hidden (view full) ---

2296int
2297kqfd_register(int fd, struct kevent *kev, struct thread *td, int waitok)
2298{
2299 struct kqueue *kq;
2300 struct file *fp;
2301 cap_rights_t rights;
2302 int error;
2303
1026 if (error)
1027 goto done;
1028
1029 if ((kev->flags & EV_ADD) == EV_ADD && kqueue_expand(kq, fops,
1030 kev->ident, 0) != 0) {
1031 /* try again */
1032 fdrop(fp, td);
1033 fp = NULL;

--- 1269 unchanged lines hidden (view full) ---

2303int
2304kqfd_register(int fd, struct kevent *kev, struct thread *td, int waitok)
2305{
2306 struct kqueue *kq;
2307 struct file *fp;
2308 cap_rights_t rights;
2309 int error;
2310
2304 error = fget(td, fd, cap_rights_init(&rights, CAP_POST_EVENT), &fp);
2311 error = fget(td, fd, cap_rights_init(&rights, CAP_KQUEUE_CHANGE), &fp);
2305 if (error != 0)
2306 return (error);
2307 if ((error = kqueue_acquire(fp, &kq)) != 0)
2308 goto noacquire;
2309
2310 error = kqueue_register(kq, kev, td, waitok);
2311
2312 kqueue_release(kq, 0);
2313
2314noacquire:
2315 fdrop(fp, td);
2316
2317 return error;
2318}
2312 if (error != 0)
2313 return (error);
2314 if ((error = kqueue_acquire(fp, &kq)) != 0)
2315 goto noacquire;
2316
2317 error = kqueue_register(kq, kev, td, waitok);
2318
2319 kqueue_release(kq, 0);
2320
2321noacquire:
2322 fdrop(fp, td);
2323
2324 return error;
2325}