kern_event.c (cd72f2180bfff020d03180e6eba1c3a0e0125468) | kern_event.c (48e3128b34dad9618402f1f4095f7655e779843c) |
---|---|
1/*- 2 * Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 143 unchanged lines hidden (view full) --- 152 153 return (fo_kqfilter(kn->kn_fp, kn)); 154} 155 156/*ARGSUSED*/ 157static int 158kqueue_kqfilter(struct file *fp, struct knote *kn) 159{ | 1/*- 2 * Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 143 unchanged lines hidden (view full) --- 152 153 return (fo_kqfilter(kn->kn_fp, kn)); 154} 155 156/*ARGSUSED*/ 157static int 158kqueue_kqfilter(struct file *fp, struct knote *kn) 159{ |
160 struct kqueue *kq = kn->kn_fp->un_data.kqueue; | 160 struct kqueue *kq = kn->kn_fp->f_data; |
161 162 if (kn->kn_filter != EVFILT_READ) 163 return (1); 164 165 kn->kn_fop = &kqread_filtops; 166 SLIST_INSERT_HEAD(&kq->kq_sel.si_note, kn, kn_selnext); 167 return (0); 168} 169 170static void 171filt_kqdetach(struct knote *kn) 172{ | 161 162 if (kn->kn_filter != EVFILT_READ) 163 return (1); 164 165 kn->kn_fop = &kqread_filtops; 166 SLIST_INSERT_HEAD(&kq->kq_sel.si_note, kn, kn_selnext); 167 return (0); 168} 169 170static void 171filt_kqdetach(struct knote *kn) 172{ |
173 struct kqueue *kq = kn->kn_fp->un_data.kqueue; | 173 struct kqueue *kq = kn->kn_fp->f_data; |
174 175 SLIST_REMOVE(&kq->kq_sel.si_note, kn, knote, kn_selnext); 176} 177 178/*ARGSUSED*/ 179static int 180filt_kqueue(struct knote *kn, long hint) 181{ | 174 175 SLIST_REMOVE(&kq->kq_sel.si_note, kn, knote, kn_selnext); 176} 177 178/*ARGSUSED*/ 179static int 180filt_kqueue(struct knote *kn, long hint) 181{ |
182 struct kqueue *kq = kn->kn_fp->un_data.kqueue; | 182 struct kqueue *kq = kn->kn_fp->f_data; |
183 184 kn->kn_data = kq->kq_count; 185 return (kn->kn_data > 0); 186} 187 188static int 189filt_procattach(struct knote *kn) 190{ --- 182 unchanged lines hidden (view full) --- 373 goto done2; 374 kq = malloc(sizeof(struct kqueue), M_KQUEUE, M_WAITOK | M_ZERO); 375 TAILQ_INIT(&kq->kq_head); 376 FILE_LOCK(fp); 377 fp->f_flag = FREAD | FWRITE; 378 fp->f_type = DTYPE_KQUEUE; 379 fp->f_ops = &kqueueops; 380 TAILQ_INIT(&kq->kq_head); | 183 184 kn->kn_data = kq->kq_count; 185 return (kn->kn_data > 0); 186} 187 188static int 189filt_procattach(struct knote *kn) 190{ --- 182 unchanged lines hidden (view full) --- 373 goto done2; 374 kq = malloc(sizeof(struct kqueue), M_KQUEUE, M_WAITOK | M_ZERO); 375 TAILQ_INIT(&kq->kq_head); 376 FILE_LOCK(fp); 377 fp->f_flag = FREAD | FWRITE; 378 fp->f_type = DTYPE_KQUEUE; 379 fp->f_ops = &kqueueops; 380 TAILQ_INIT(&kq->kq_head); |
381 fp->un_data.kqueue = kq; | 381 fp->f_data = kq; |
382 FILE_UNLOCK(fp); 383 FILEDESC_LOCK(fdp); 384 td->td_retval[0] = fd; 385 if (fdp->fd_knlistsize < 0) 386 fdp->fd_knlistsize = 0; /* this process has a kq */ 387 FILEDESC_UNLOCK(fdp); 388 kq->kq_fdp = fdp; 389done2: --- 32 unchanged lines hidden (view full) --- 422 if (uap->timeout != NULL) { 423 error = copyin(uap->timeout, &ts, sizeof(ts)); 424 if (error) 425 goto done_nogiant; 426 uap->timeout = &ts; 427 } 428 mtx_lock(&Giant); 429 | 382 FILE_UNLOCK(fp); 383 FILEDESC_LOCK(fdp); 384 td->td_retval[0] = fd; 385 if (fdp->fd_knlistsize < 0) 386 fdp->fd_knlistsize = 0; /* this process has a kq */ 387 FILEDESC_UNLOCK(fdp); 388 kq->kq_fdp = fdp; 389done2: --- 32 unchanged lines hidden (view full) --- 422 if (uap->timeout != NULL) { 423 error = copyin(uap->timeout, &ts, sizeof(ts)); 424 if (error) 425 goto done_nogiant; 426 uap->timeout = &ts; 427 } 428 mtx_lock(&Giant); 429 |
430 kq = fp->un_data.kqueue; | 430 kq = fp->f_data; |
431 nerrors = 0; 432 433 while (uap->nchanges > 0) { 434 n = uap->nchanges > KQ_NEVENTS ? KQ_NEVENTS : uap->nchanges; 435 error = copyin(uap->changelist, kq->kq_kev, 436 n * sizeof(struct kevent)); 437 if (error) 438 goto done; --- 206 unchanged lines hidden (view full) --- 645 struct kqueue *kq; 646 struct kevent *kevp; 647 struct timeval atv, rtv, ttv; 648 struct knote *kn, marker; 649 int s, count, timeout, nkev = 0, error = 0; 650 651 FILE_LOCK_ASSERT(fp, MA_NOTOWNED); 652 | 431 nerrors = 0; 432 433 while (uap->nchanges > 0) { 434 n = uap->nchanges > KQ_NEVENTS ? KQ_NEVENTS : uap->nchanges; 435 error = copyin(uap->changelist, kq->kq_kev, 436 n * sizeof(struct kevent)); 437 if (error) 438 goto done; --- 206 unchanged lines hidden (view full) --- 645 struct kqueue *kq; 646 struct kevent *kevp; 647 struct timeval atv, rtv, ttv; 648 struct knote *kn, marker; 649 int s, count, timeout, nkev = 0, error = 0; 650 651 FILE_LOCK_ASSERT(fp, MA_NOTOWNED); 652 |
653 kq = fp->un_data.kqueue; | 653 kq = fp->f_data; |
654 count = maxevents; 655 if (count == 0) 656 goto done; 657 658 if (tsp != NULL) { 659 TIMESPEC_TO_TIMEVAL(&atv, tsp); 660 if (itimerfix(&atv)) { 661 error = EINVAL; --- 139 unchanged lines hidden (view full) --- 801static int 802kqueue_poll(struct file *fp, int events, struct ucred *active_cred, 803 struct thread *td) 804{ 805 struct kqueue *kq; 806 int revents = 0; 807 int s = splnet(); 808 | 654 count = maxevents; 655 if (count == 0) 656 goto done; 657 658 if (tsp != NULL) { 659 TIMESPEC_TO_TIMEVAL(&atv, tsp); 660 if (itimerfix(&atv)) { 661 error = EINVAL; --- 139 unchanged lines hidden (view full) --- 801static int 802kqueue_poll(struct file *fp, int events, struct ucred *active_cred, 803 struct thread *td) 804{ 805 struct kqueue *kq; 806 int revents = 0; 807 int s = splnet(); 808 |
809 kq = fp->un_data.kqueue; | 809 kq = fp->f_data; |
810 if (events & (POLLIN | POLLRDNORM)) { 811 if (kq->kq_count) { 812 revents |= events & (POLLIN | POLLRDNORM); 813 } else { 814 selrecord(td, &kq->kq_sel); 815 kq->kq_state |= KQ_SEL; 816 } 817 } 818 splx(s); 819 return (revents); 820} 821 822/*ARGSUSED*/ 823static int 824kqueue_stat(struct file *fp, struct stat *st, struct ucred *active_cred, 825 struct thread *td) 826{ 827 struct kqueue *kq; 828 | 810 if (events & (POLLIN | POLLRDNORM)) { 811 if (kq->kq_count) { 812 revents |= events & (POLLIN | POLLRDNORM); 813 } else { 814 selrecord(td, &kq->kq_sel); 815 kq->kq_state |= KQ_SEL; 816 } 817 } 818 splx(s); 819 return (revents); 820} 821 822/*ARGSUSED*/ 823static int 824kqueue_stat(struct file *fp, struct stat *st, struct ucred *active_cred, 825 struct thread *td) 826{ 827 struct kqueue *kq; 828 |
829 kq = fp->un_data.kqueue; | 829 kq = fp->f_data; |
830 bzero((void *)st, sizeof(*st)); 831 st->st_size = kq->kq_count; 832 st->st_blksize = sizeof(struct kevent); 833 st->st_mode = S_IFIFO; 834 return (0); 835} 836 837/*ARGSUSED*/ 838static int 839kqueue_close(struct file *fp, struct thread *td) 840{ | 830 bzero((void *)st, sizeof(*st)); 831 st->st_size = kq->kq_count; 832 st->st_blksize = sizeof(struct kevent); 833 st->st_mode = S_IFIFO; 834 return (0); 835} 836 837/*ARGSUSED*/ 838static int 839kqueue_close(struct file *fp, struct thread *td) 840{ |
841 struct kqueue *kq = fp->un_data.kqueue; | 841 struct kqueue *kq = fp->f_data; |
842 struct filedesc *fdp = td->td_proc->p_fd; 843 struct knote **knp, *kn, *kn0; 844 int i; 845 846 FILEDESC_LOCK(fdp); 847 for (i = 0; i < fdp->fd_knlistsize; i++) { 848 knp = &SLIST_FIRST(&fdp->fd_knlist[i]); 849 kn = *knp; --- 30 unchanged lines hidden (view full) --- 880 knp = &SLIST_NEXT(kn, kn_link); 881 } 882 kn = kn0; 883 } 884 } 885 } 886 FILEDESC_UNLOCK(fdp); 887 free(kq, M_KQUEUE); | 842 struct filedesc *fdp = td->td_proc->p_fd; 843 struct knote **knp, *kn, *kn0; 844 int i; 845 846 FILEDESC_LOCK(fdp); 847 for (i = 0; i < fdp->fd_knlistsize; i++) { 848 knp = &SLIST_FIRST(&fdp->fd_knlist[i]); 849 kn = *knp; --- 30 unchanged lines hidden (view full) --- 880 knp = &SLIST_NEXT(kn, kn_link); 881 } 882 kn = kn0; 883 } 884 } 885 } 886 FILEDESC_UNLOCK(fdp); 887 free(kq, M_KQUEUE); |
888 fp->un_data.kqueue = NULL; | 888 fp->f_data = NULL; |
889 890 return (0); 891} 892 893static void 894kqueue_wakeup(struct kqueue *kq) 895{ 896 --- 199 unchanged lines hidden --- | 889 890 return (0); 891} 892 893static void 894kqueue_wakeup(struct kqueue *kq) 895{ 896 --- 199 unchanged lines hidden --- |