1
0
mirror of https://github.com/openbsd/src.git synced 2025-01-04 15:25:38 -08:00

In kq_del(), delete matching EV_ADD entries to prevent libevent from

passing both EV_ADD and EV_DELETE for the same fd to kevent().

ok visa
This commit is contained in:
yasuoka 2024-03-23 22:51:49 +00:00
parent f7d60097d8
commit a96d88d343

View File

@ -1,4 +1,4 @@
/* $OpenBSD: kqueue.c,v 1.42 2022/12/27 23:05:55 jmc Exp $ */ /* $OpenBSD: kqueue.c,v 1.43 2024/03/23 22:51:49 yasuoka Exp $ */
/* /*
* Copyright 2000-2002 Niels Provos <provos@citi.umich.edu> * Copyright 2000-2002 Niels Provos <provos@citi.umich.edu>
@ -358,6 +358,7 @@ kq_add(void *arg, struct event *ev)
static int static int
kq_del(void *arg, struct event *ev) kq_del(void *arg, struct event *ev)
{ {
int i, j;
struct kqop *kqop = arg; struct kqop *kqop = arg;
struct kevent kev; struct kevent kev;
@ -391,6 +392,21 @@ kq_del(void *arg, struct event *ev)
return (0); return (0);
} }
for (i = j = 0; i < kqop->nchanges; i++) {
if (kqop->changes[i].udata == ev &&
(kqop->changes[i].flags & EV_ADD) != 0)
continue; /* delete this */
if (i != j)
memcpy(&kqop->changes[j], &kqop->changes[i],
sizeof(struct kevent));
j++;
}
if (kqop->nchanges != j) {
kqop->nchanges = j;
ev->ev_flags &= ~EVLIST_X_KQINKERNEL;
return (0);
}
if (ev->ev_events & EV_READ) { if (ev->ev_events & EV_READ) {
memset(&kev, 0, sizeof(kev)); memset(&kev, 0, sizeof(kev));
kev.ident = ev->ev_fd; kev.ident = ev->ev_fd;