MCPcopy Create free account
hub / github.com/F-Stack/f-stack / knote_fdclose

Function knote_fdclose

freebsd/kern/kern_event.c:2555–2592  ·  view source on GitHub ↗

* Remove all knotes referencing a specified fd must be called with FILEDESC * lock. This prevents a race where a new fd comes along and occupies the * entry and we attach a knote to the fd. */

Source from the content-addressed store, hash-verified

2553 * entry and we attach a knote to the fd.
2554 */
2555void
2556knote_fdclose(struct thread *td, int fd)
2557{
2558 struct filedesc *fdp = td->td_proc->p_fd;
2559 struct kqueue *kq;
2560 struct knote *kn;
2561 int influx;
2562
2563 FILEDESC_XLOCK_ASSERT(fdp);
2564
2565 /*
2566 * We shouldn't have to worry about new kevents appearing on fd
2567 * since filedesc is locked.
2568 */
2569 TAILQ_FOREACH(kq, &fdp->fd_kqlist, kq_list) {
2570 KQ_LOCK(kq);
2571
2572again:
2573 influx = 0;
2574 while (kq->kq_knlistsize > fd &&
2575 (kn = SLIST_FIRST(&kq->kq_knlist[fd])) != NULL) {
2576 if (kn_in_flux(kn)) {
2577 /* someone else might be waiting on our knote */
2578 if (influx)
2579 wakeup(kq);
2580 kq->kq_state |= KQ_FLUXWAIT;
2581 msleep(kq, &kq->kq_lock, PSOCK, "kqflxwt", 0);
2582 goto again;
2583 }
2584 kn_enter_flux(kn);
2585 KQ_UNLOCK(kq);
2586 influx = 1;
2587 knote_drop(kn, td);
2588 KQ_LOCK(kq);
2589 }
2590 KQ_UNLOCK_FLUX(kq);
2591 }
2592}
2593
2594static int
2595knote_attach(struct knote *kn, struct kqueue *kq)

Callers 2

closefp_implFunction · 0.85
fdsetugidsafetyFunction · 0.85

Calls 4

kn_in_fluxFunction · 0.85
kn_enter_fluxFunction · 0.85
knote_dropFunction · 0.85
wakeupFunction · 0.70

Tested by

no test coverage detected