diff options
author | 2005-04-19 08:07:45 +0000 | |
---|---|---|
committer | 2005-04-19 08:07:45 +0000 | |
commit | 97617856cbf642de05ad59901d31f8c1c9659e6d (patch) | |
tree | 59da653db81b56f98f29d1d81277dcb0f6cd7651 /lib/libevent/kqueue.c | |
parent | do not attempt to list which archs are relevant to which machdep (diff) | |
download | wireguard-openbsd-97617856cbf642de05ad59901d31f8c1c9659e6d.tar.xz wireguard-openbsd-97617856cbf642de05ad59901d31f8c1c9659e6d.zip |
backout. not discussed, and very wrong. bad brad
Diffstat (limited to 'lib/libevent/kqueue.c')
-rw-r--r-- | lib/libevent/kqueue.c | 63 |
1 files changed, 34 insertions, 29 deletions
diff --git a/lib/libevent/kqueue.c b/lib/libevent/kqueue.c index 0431c61bb47..78309cd6e8d 100644 --- a/lib/libevent/kqueue.c +++ b/lib/libevent/kqueue.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kqueue.c,v 1.13 2005/04/19 02:03:12 brad Exp $ */ +/* $OpenBSD: kqueue.c,v 1.14 2005/04/19 08:07:45 deraadt Exp $ */ /* * Copyright 2000-2002 Niels Provos <provos@citi.umich.edu> @@ -44,18 +44,29 @@ #include <string.h> #include <unistd.h> #include <errno.h> +#include <err.h> #ifdef HAVE_INTTYPES_H #include <inttypes.h> #endif -#if defined(HAVE_INTTYPES_H) && !defined(__OpenBSD__) && !defined(__FreeBSD__) +#ifdef USE_LOG +#include "log.h" +#else +#define LOG_DBG(x) +#define log_error warn +#endif + +#if defined(HAVE_INTTYPES_H) && !defined(__OpenBSD__) #define INTPTR(x) (intptr_t)x #else #define INTPTR(x) x #endif #include "event.h" -#include "log.h" + +extern struct event_list timequeue; +extern struct event_list eventqueue; +extern struct event_list addqueue; #define EVLIST_X_KQINKERNEL 0x1000 @@ -67,13 +78,13 @@ struct kqop { struct kevent *events; int nevents; int kq; -}; +} kqueueop; void *kq_init (void); int kq_add (void *, struct event *); int kq_del (void *, struct event *); -int kq_recalc (struct event_base *, void *, int); -int kq_dispatch (struct event_base *, void *, struct timeval *); +int kq_recalc (void *, int); +int kq_dispatch (void *, struct timeval *); int kq_insert (struct kqop *, struct kevent *); const struct eventop kqops = { @@ -89,44 +100,38 @@ void * kq_init(void) { int kq; - struct kqop *kqueueop; /* Disable kqueue when this environment variable is set */ if (!issetugid() && getenv("EVENT_NOKQUEUE")) return (NULL); - if (!(kqueueop = calloc(1, sizeof(struct kqop)))) - return (NULL); + memset(&kqueueop, 0, sizeof(kqueueop)); /* Initalize the kernel queue */ if ((kq = kqueue()) == -1) { - event_warn("kqueue"); - free (kqueueop); + log_error("kqueue"); return (NULL); } - kqueueop->kq = kq; + kqueueop.kq = kq; /* Initalize fields */ - kqueueop->changes = malloc(NEVENT * sizeof(struct kevent)); - if (kqueueop->changes == NULL) { - free (kqueueop); + kqueueop.changes = malloc(NEVENT * sizeof(struct kevent)); + if (kqueueop.changes == NULL) return (NULL); - } - kqueueop->events = malloc(NEVENT * sizeof(struct kevent)); - if (kqueueop->events == NULL) { - free (kqueueop->changes); - free (kqueueop); + kqueueop.events = malloc(NEVENT * sizeof(struct kevent)); + if (kqueueop.events == NULL) { + free (kqueueop.changes); return (NULL); } - kqueueop->nevents = NEVENT; + kqueueop.nevents = NEVENT; - return (kqueueop); + return (&kqueueop); } int -kq_recalc(struct event_base *base, void *arg, int max) +kq_recalc(void *arg, int max) { return (0); } @@ -145,7 +150,7 @@ kq_insert(struct kqop *kqop, struct kevent *kev) newchange = realloc(kqop->changes, nevents * sizeof(struct kevent)); if (newchange == NULL) { - event_warn("%s: malloc", __func__); + log_error("%s: malloc", __func__); return (-1); } kqop->changes = newchange; @@ -158,7 +163,7 @@ kq_insert(struct kqop *kqop, struct kevent *kev) * the next realloc will pick it up. */ if (newresult == NULL) { - event_warn("%s: malloc", __func__); + log_error("%s: malloc", __func__); return (-1); } kqop->events = newresult; @@ -168,7 +173,7 @@ kq_insert(struct kqop *kqop, struct kevent *kev) memcpy(&kqop->changes[kqop->nchanges++], kev, sizeof(struct kevent)); - event_debug(("%s: fd %d %s%s", + LOG_DBG((LOG_MISC, 70, "%s: fd %d %s%s", __func__, kev->ident, kev->filter == EVFILT_READ ? "EVFILT_READ" : "EVFILT_WRITE", kev->flags == EV_DELETE ? " (del)" : "")); @@ -183,7 +188,7 @@ kq_sighandler(int sig) } int -kq_dispatch(struct event_base *base, void *arg, struct timeval *tv) +kq_dispatch(void *arg, struct timeval *tv) { struct kqop *kqop = arg; struct kevent *changes = kqop->changes; @@ -199,14 +204,14 @@ kq_dispatch(struct event_base *base, void *arg, struct timeval *tv) kqop->nchanges = 0; if (res == -1) { if (errno != EINTR) { - event_warn("kevent"); + log_error("kevent"); return (-1); } return (0); } - event_debug(("%s: kevent reports %d", __func__, res)); + LOG_DBG((LOG_MISC, 80, "%s: kevent reports %d", __func__, res)); for (i = 0; i < res; i++) { int which = 0; |