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

Function knote_fork

freebsd/kern/kern_event.c:529–611  ·  view source on GitHub ↗

* Called when the process forked. It mostly does the same as the * knote(), activating all knotes registered to be activated when the * process forked. Additionally, for each knote attached to the * parent, check whether user wants to track the new process. If so * attach a new knote to it, and immediately report an event with the * child's pid. */

Source from the content-addressed store, hash-verified

527 * child's pid.
528 */
529void
530knote_fork(struct knlist *list, int pid)
531{
532 struct kqueue *kq;
533 struct knote *kn;
534 struct kevent kev;
535 int error;
536
537 MPASS(list != NULL);
538 KNL_ASSERT_LOCKED(list);
539 if (SLIST_EMPTY(&list->kl_list))
540 return;
541
542 memset(&kev, 0, sizeof(kev));
543 SLIST_FOREACH(kn, &list->kl_list, kn_selnext) {
544 kq = kn->kn_kq;
545 KQ_LOCK(kq);
546 if (kn_in_flux(kn) && (kn->kn_status & KN_SCAN) == 0) {
547 KQ_UNLOCK(kq);
548 continue;
549 }
550
551 /*
552 * The same as knote(), activate the event.
553 */
554 if ((kn->kn_sfflags & NOTE_TRACK) == 0) {
555 if (kn->kn_fop->f_event(kn, NOTE_FORK))
556 KNOTE_ACTIVATE(kn, 1);
557 KQ_UNLOCK(kq);
558 continue;
559 }
560
561 /*
562 * The NOTE_TRACK case. In addition to the activation
563 * of the event, we need to register new events to
564 * track the child. Drop the locks in preparation for
565 * the call to kqueue_register().
566 */
567 kn_enter_flux(kn);
568 KQ_UNLOCK(kq);
569 list->kl_unlock(list->kl_lockarg);
570
571 /*
572 * Activate existing knote and register tracking knotes with
573 * new process.
574 *
575 * First register a knote to get just the child notice. This
576 * must be a separate note from a potential NOTE_EXIT
577 * notification since both NOTE_CHILD and NOTE_EXIT are defined
578 * to use the data field (in conflicting ways).
579 */
580 kev.ident = pid;
581 kev.filter = kn->kn_filter;
582 kev.flags = kn->kn_flags | EV_ADD | EV_ENABLE | EV_ONESHOT |
583 EV_FLAG2;
584 kev.fflags = kn->kn_sfflags;
585 kev.data = kn->kn_id; /* parent */
586 kev.udata = kn->kn_kevent.udata;/* preserve udata */

Callers 1

do_forkFunction · 0.85

Calls 5

memsetFunction · 0.85
kn_in_fluxFunction · 0.85
kn_enter_fluxFunction · 0.85
kqueue_registerFunction · 0.85
kn_leave_fluxFunction · 0.85

Tested by

no test coverage detected