EXPERIMENTAL: tevent_kqueue support

Stefan (metze) Metzmacher metze at samba.org
Sun Feb 17 09:07:30 MST 2013


Hi Timur,

I've started with a tevent_kqueue implementation
(just looking at the man page).

It compiles for me on linux with the 2nd HACK patch.

Can you have a look and test it?

@Jeremy: we may want to pick up some of the simplified logic into the
epoll backend:
         kqueue_update_fd_event() instead of
         epoll_add_event/epoll_mod_event/epoll_del_event/epoll_change_event.

I'm also thinking about having a fallback handler in the kqueue backend
and use it if available from the standard backend.

metze
-------------- next part --------------
From eb1ee84eb1757ccebed8d85f577249f2882026b7 Mon Sep 17 00:00:00 2001
From: Stefan Metzmacher <metze at samba.org>
Date: Sun, 17 Feb 2013 15:03:03 +0100
Subject: [PATCH 1/2] TODO/UNTESTED: tevent: add kqueue backend

---
 lib/tevent/libtevent.m4      |    7 +
 lib/tevent/tevent.c          |    3 +
 lib/tevent/tevent_internal.h |    3 +
 lib/tevent/tevent_kqueue.c   |  496 ++++++++++++++++++++++++++++++++++++++++++
 lib/tevent/wscript           |    6 +
 5 files changed, 515 insertions(+)
 create mode 100644 lib/tevent/tevent_kqueue.c

diff --git a/lib/tevent/libtevent.m4 b/lib/tevent/libtevent.m4
index 5c5969b..96728fd 100644
--- a/lib/tevent/libtevent.m4
+++ b/lib/tevent/libtevent.m4
@@ -39,6 +39,13 @@ if test x"$ac_cv_header_sys_epoll_h" = x"yes" -a x"$ac_cv_func_epoll_create" = x
    AC_DEFINE(HAVE_EPOLL, 1, [Whether epoll available])
 fi
 
+AC_CHECK_HEADERS(sys/event.h)
+AC_CHECK_FUNCS(kqueue)
+if test x"$ac_cv_header_sys_event_h" = x"yes" -a x"$ac_cv_func_kqueue" = x"yes"; then
+   TEVENT_OBJ="$TEVENT_OBJ tevent_kqueue.o"
+   AC_DEFINE(HAVE_KQUEUE, 1, [Whether kqueue available])
+fi
+
 if test x"$VERSIONSCRIPT" != "x"; then
     EXPORTSFILE=tevent.exports
     AC_SUBST(EXPORTSFILE)
diff --git a/lib/tevent/tevent.c b/lib/tevent/tevent.c
index 3b273d6..c7732b3 100644
--- a/lib/tevent/tevent.c
+++ b/lib/tevent/tevent.c
@@ -126,6 +126,9 @@ static void tevent_backend_init(void)
 #ifdef HAVE_EPOLL
 	tevent_epoll_init();
 #endif
+#ifdef HAVE_KQUEUE
+	tevent_kqueue_init();
+#endif
 	tevent_standard_init();
 }
 
diff --git a/lib/tevent/tevent_internal.h b/lib/tevent/tevent_internal.h
index 8433333..da7bea879 100644
--- a/lib/tevent/tevent_internal.h
+++ b/lib/tevent/tevent_internal.h
@@ -325,6 +325,9 @@ bool tevent_epoll_set_panic_fallback(struct tevent_context *ev,
 			bool (*panic_fallback)(struct tevent_context *ev,
 					       bool replay));
 #endif
+#ifdef HAVE_KQUEUE
+bool tevent_kqueue_init(void);
+#endif
 
 
 void tevent_trace_point_callback(struct tevent_context *ev,
diff --git a/lib/tevent/tevent_kqueue.c b/lib/tevent/tevent_kqueue.c
new file mode 100644
index 0000000..3d4a6ec
--- /dev/null
+++ b/lib/tevent/tevent_kqueue.c
@@ -0,0 +1,496 @@
+/*
+   Unix SMB/CIFS implementation.
+
+   main select loop and event handling - kqueue implementation
+
+   Copyright (C) Stefan Metzmacher 2013
+
+     ** NOTE! The following LGPL license applies to the tevent
+     ** library. This does NOT imply that all of Samba is released
+     ** under the LGPL
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 3 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "replace.h"
+#include "system/filesys.h"
+#include "system/select.h"
+#include "tevent.h"
+#include "tevent_internal.h"
+#include "tevent_util.h"
+
+struct kqueue_event_context {
+	struct tevent_context *ev;
+	pid_t pid;
+	int kqueue_fd;
+};
+
+static void kqueue_panic(struct kqueue_event_context *kqueue_ev,
+			 const char *reason)
+{
+	struct tevent_context *ev = kqueue_ev->ev;
+
+	tevent_debug(ev, TEVENT_DEBUG_FATAL,
+		     "kqueue_panic: %s (%s) - calling abort()\n",
+		     reason, strerror(errno));
+	abort();
+}
+
+static int kqueue_ctx_destructor(struct kqueue_event_context *kqueue_ev)
+{
+	kqueue_ev->ev->additional_data = NULL;
+
+	if (kqueue_ev->kqueue_fd != -1) {
+		close(kqueue_ev->kqueue_fd);
+	}
+	kqueue_ev->kqueue_fd = -1;
+
+	return 0;
+}
+
+static int kqueue_event_context_init(struct tevent_context *ev)
+{
+	struct kqueue_event_context *kqueue_ev;
+
+	/*
+	 * We might be called during tevent_re_initialise()
+	 * which means we need to free our old additional_data.
+	 */
+	TALLOC_FREE(ev->additional_data);
+
+	kqueue_ev = talloc_zero(ev, struct kqueue_event_context);
+	if (kqueue_ev == NULL) {
+		return -1;
+	}
+	kqueue_ev->ev = ev;
+	kqueue_ev->pid = getpid();
+	kqueue_ev->kqueue_fd = -1;
+
+	talloc_set_destructor(kqueue_ev, kqueue_ctx_destructor);
+
+	kqueue_ev->kqueue_fd = kqueue();
+	if (kqueue_ev->kqueue_fd == -1) {
+		TALLOC_FREE(kqueue_ev);
+		tevent_debug(ev, TEVENT_DEBUG_FATAL,
+			     "Failed to create kqueue() handle.\n");
+		return -1;
+	}
+
+	if (!ev_set_close_on_exec(kqueue_ev->kqueue_fd)) {
+		tevent_debug(kqueue_ev->ev, TEVENT_DEBUG_WARNING,
+			     "kqueue_fd pid[%d] - failed to set close-on-exec, "
+			     "file descriptor may be leaked to children.\n",
+			     kqueue_ev->pid);
+	}
+
+	ev->additional_data = kqueue_ev;
+	return 0;
+}
+
+static void kqueue_update_fd_event(struct kqueue_event_context *kqueue_ev,
+				   struct tevent_fd *fde);
+
+static void kqueue_check_reopen(struct kqueue_event_context *kqueue_ev)
+{
+	struct tevent_fd *fde;
+
+	if (kqueue_ev->pid == getpid()) {
+		return;
+	}
+	kqueue_ev->pid = getpid();
+
+	close(kqueue_ev->kqueue_fd);
+	kqueue_ev->kqueue_fd = kqueue();
+	if (kqueue_ev->kqueue_fd == -1) {
+		kqueue_panic(kqueue_ev, "kqueue() failed");
+		return;
+	}
+
+	if (!ev_set_close_on_exec(kqueue_ev->kqueue_fd)) {
+		tevent_debug(kqueue_ev->ev, TEVENT_DEBUG_WARNING,
+			     "kqueue_fd pid[%d] - failed to set close-on-exec, "
+			     "file descriptor may be leaked to children.\n",
+			     kqueue_ev->pid);
+	}
+
+	for (fde=kqueue_ev->ev->fd_events;fde;fde=fde->next) {
+		fde->additional_flags = 0;
+		kqueue_update_fd_event(kqueue_ev, fde);
+	}
+}
+
+#define KQUEUE_ADDITIONAL_FD_FLAG_HAS_READ		(1<<0)
+#define KQUEUE_ADDITIONAL_FD_FLAG_DISABLED_READ		(1<<1)
+#define KQUEUE_ADDITIONAL_FD_FLAG_HAS_WRITE		(1<<2)
+#define KQUEUE_ADDITIONAL_FD_FLAG_DISABLED_WRITE	(1<<3)
+#define KQUEUE_ADDITIONAL_FD_FLAG_REPORT_ERROR		(1<<4)
+#define KQUEUE_ADDITIONAL_FD_FLAG_GOT_ERROR		(1<<5)
+
+static void kqueue_update_fd_event(struct kqueue_event_context *kqueue_ev,
+				   struct tevent_fd *fde)
+{
+	bool add_read = false;
+	bool enable_read = false;
+	bool disable_read = false;
+	bool delete_read = false;
+	bool add_write = false;
+	bool enable_write = false;
+	bool disable_write = false;
+	bool delete_write = false;
+	bool got_error = (fde->additional_flags & KQUEUE_ADDITIONAL_FD_FLAG_GOT_ERROR);
+	struct kevent kev;
+	int ret;
+
+	if (fde->additional_flags & KQUEUE_ADDITIONAL_FD_FLAG_DISABLED_WRITE) {
+		if (got_error) {
+			delete_write = true;
+		} else if (fde->flags & TEVENT_FD_WRITE) {
+			enable_write = true;
+		} else if (fde->flags == 0) {
+			delete_write = true;
+		}
+	} else if (fde->additional_flags & KQUEUE_ADDITIONAL_FD_FLAG_HAS_WRITE) {
+		if (got_error) {
+			delete_write = true;
+		} else if (fde->flags == 0) {
+			delete_write = true;
+		} else if (!(fde->flags & TEVENT_FD_WRITE)) {
+			disable_write = true;
+		}
+	} else {
+		if (got_error) {
+			/* nothing */
+		} else if (fde->flags & TEVENT_FD_WRITE) {
+			add_write = true;
+		}
+	}
+
+	if (fde->additional_flags & KQUEUE_ADDITIONAL_FD_FLAG_DISABLED_READ) {
+		if (fde->flags & TEVENT_FD_READ) {
+			enable_read = true;
+		} else if (fde->flags == 0) {
+			delete_read = true;
+		}
+	} else if (fde->additional_flags & KQUEUE_ADDITIONAL_FD_FLAG_HAS_READ) {
+		if (fde->flags == 0) {
+			delete_read = true;
+		} else if (!(fde->flags & TEVENT_FD_READ)) {
+			disable_read = true;
+		}
+	} else {
+		if (fde->flags & TEVENT_FD_READ) {
+			add_read = true;
+		}
+	}
+
+	if (add_write) {
+		EV_SET(&kev, fde->fd, EVFILT_WRITE, EV_ADD,
+		       0 /* fflags */, NULL /* data */,
+		       fde);
+		ret = kevent(kqueue_ev->kqueue_fd, &kev, 1, NULL, 0, NULL);
+		if (ret != 0) {
+			kqueue_panic(kqueue_ev, "EVFILT_WRITE EV_ADD failed");
+			return;
+		}
+
+		fde->additional_flags |= KQUEUE_ADDITIONAL_FD_FLAG_HAS_WRITE;
+	} else if (enable_write) {
+		EV_SET(&kev, fde->fd, EVFILT_WRITE, EV_ENABLE,
+		       0 /* fflags */, NULL /* data */,
+		       fde);
+		ret = kevent(kqueue_ev->kqueue_fd, &kev, 1, NULL, 0, NULL);
+		if (ret != 0) {
+			kqueue_panic(kqueue_ev, "EVFILT_WRITE EV_ENABLE failed");
+			return;
+		}
+
+		fde->additional_flags &= ~KQUEUE_ADDITIONAL_FD_FLAG_DISABLED_WRITE;
+	} else if (disable_write) {
+		EV_SET(&kev, fde->fd, EVFILT_WRITE, EV_DISABLE,
+		       0 /* fflags */, NULL /* data */,
+		       fde);
+		ret = kevent(kqueue_ev->kqueue_fd, &kev, 1, NULL, 0, NULL);
+		if (ret != 0) {
+			kqueue_panic(kqueue_ev, "EVFILT_WRITE EV_DISABLE failed");
+			return;
+		}
+
+		fde->additional_flags |= KQUEUE_ADDITIONAL_FD_FLAG_DISABLED_WRITE;
+	} else if (delete_write) {
+		EV_SET(&kev, fde->fd, EVFILT_WRITE, EV_DELETE,
+		       0 /* fflags */, NULL /* data */,
+		       fde);
+		ret = kevent(kqueue_ev->kqueue_fd, &kev, 1, NULL, 0, NULL);
+		if (ret != 0) {
+			kqueue_panic(kqueue_ev, "EVFILT_WRITE EV_DEL failed");
+			return;
+		}
+
+		fde->additional_flags &= ~KQUEUE_ADDITIONAL_FD_FLAG_HAS_WRITE;
+		fde->additional_flags &= ~KQUEUE_ADDITIONAL_FD_FLAG_DISABLED_WRITE;
+	}
+
+	if (add_read) {
+		EV_SET(&kev, fde->fd, EVFILT_READ, EV_ADD,
+		       0 /* fflags */, NULL /* data */,
+		       fde);
+		ret = kevent(kqueue_ev->kqueue_fd, &kev, 1, NULL, 0, NULL);
+		if (ret != 0) {
+			kqueue_panic(kqueue_ev, "EVFILT_READ EV_ADD failed");
+			return;
+		}
+
+		fde->additional_flags |= KQUEUE_ADDITIONAL_FD_FLAG_HAS_READ;
+		fde->additional_flags |= KQUEUE_ADDITIONAL_FD_FLAG_REPORT_ERROR;
+	} else if (enable_read) {
+		EV_SET(&kev, fde->fd, EVFILT_READ, EV_ENABLE,
+		       0 /* fflags */, NULL /* data */,
+		       fde);
+		ret = kevent(kqueue_ev->kqueue_fd, &kev, 1, NULL, 0, NULL);
+		if (ret != 0) {
+			kqueue_panic(kqueue_ev, "EVFILT_READ EV_ENABLE failed");
+			return;
+		}
+
+		fde->additional_flags &= ~KQUEUE_ADDITIONAL_FD_FLAG_DISABLED_READ;
+		fde->additional_flags |= KQUEUE_ADDITIONAL_FD_FLAG_REPORT_ERROR;
+	} else if (disable_read) {
+		EV_SET(&kev, fde->fd, EVFILT_READ, EV_DISABLE,
+		       0 /* fflags */, NULL /* data */,
+		       fde);
+		ret = kevent(kqueue_ev->kqueue_fd, &kev, 1, NULL, 0, NULL);
+		if (ret != 0) {
+			kqueue_panic(kqueue_ev, "EVFILT_READ EV_DISABLE failed");
+			return;
+		}
+
+		fde->additional_flags |= KQUEUE_ADDITIONAL_FD_FLAG_DISABLED_READ;
+		fde->additional_flags &= ~KQUEUE_ADDITIONAL_FD_FLAG_REPORT_ERROR;
+	} else if (delete_read) {
+		EV_SET(&kev, fde->fd, EVFILT_READ, EV_DELETE,
+		       0 /* fflags */, NULL /* data */,
+		       fde);
+		ret = kevent(kqueue_ev->kqueue_fd, &kev, 1, NULL, 0, NULL);
+		if (ret != 0) {
+			kqueue_panic(kqueue_ev, "EVFILT_READ EV_DEL failed");
+			return;
+		}
+
+		fde->additional_flags &= ~KQUEUE_ADDITIONAL_FD_FLAG_HAS_READ;
+		fde->additional_flags &= ~KQUEUE_ADDITIONAL_FD_FLAG_DISABLED_READ;
+		fde->additional_flags &= ~KQUEUE_ADDITIONAL_FD_FLAG_REPORT_ERROR;
+	}
+}
+
+/*
+  destroy an fd_event
+*/
+static int kqueue_event_fd_destructor(struct tevent_fd *fde)
+{
+	struct tevent_context *ev = fde->event_ctx;
+
+	if (ev) {
+		struct kqueue_event_context *kqueue_ev =
+			talloc_get_type_abort(ev->additional_data,
+			struct kqueue_event_context);
+		int flags = fde->flags;
+
+		kqueue_check_reopen(kqueue_ev);
+
+		fde->flags = 0;
+		kqueue_update_fd_event(kqueue_ev, fde);
+		fde->flags = flags;
+	}
+
+	return tevent_common_fd_destructor(fde);
+}
+
+static struct tevent_fd *kqueue_event_add_fd(struct tevent_context *ev, TALLOC_CTX *mem_ctx,
+					    int fd, uint16_t flags,
+					    tevent_fd_handler_t handler,
+					    void *private_data,
+					    const char *handler_name,
+					    const char *location)
+{
+	struct kqueue_event_context *kqueue_ev =
+		talloc_get_type_abort(ev->additional_data,
+		struct kqueue_event_context);
+	struct tevent_fd *fde;
+
+	fde = tevent_common_add_fd(ev, mem_ctx, fd, flags,
+				   handler, private_data,
+				   handler_name, location);
+	if (fde == NULL) {
+		return NULL;
+	}
+	talloc_set_destructor(fde, kqueue_event_fd_destructor);
+
+	kqueue_check_reopen(kqueue_ev);
+
+	kqueue_update_fd_event(kqueue_ev, fde);
+
+	return fde;
+}
+
+/*
+  set the fd event flags
+*/
+static void kqueue_event_set_fd_flags(struct tevent_fd *fde, uint16_t flags)
+{
+	struct tevent_context *ev;
+	struct kqueue_event_context *kqueue_ev;
+
+	if (fde->flags == flags) return;
+
+	ev = fde->event_ctx;
+	kqueue_ev = talloc_get_type_abort(ev->additional_data,
+					  struct kqueue_event_context);
+
+	fde->flags = flags;
+
+	kqueue_check_reopen(kqueue_ev);
+	kqueue_update_fd_event(kqueue_ev, fde);
+}
+
+/*
+  event loop handling using kqueue
+*/
+static int kqueue_event_loop(struct kqueue_event_context *kqueue_ev, struct timeval *tvalp)
+{
+	int ret, i;
+#define MAXEVENTS 1
+	struct kevent kevs[MAXEVENTS];
+	struct timespec _ts;
+	const struct timespec *timeout = NULL;
+	int kevent_errno;
+
+	if (kqueue_ev->ev->signal_events &&
+	    tevent_common_check_signal(kqueue_ev->ev)) {
+		return 0;
+	}
+
+	if (tvalp) {
+		_ts.tv_sec = tvalp->tv_sec;
+		_ts.tv_nsec = tvalp->tv_usec * 1000;
+		timeout = &_ts;
+	}
+
+	tevent_trace_point_callback(kqueue_ev->ev, TEVENT_TRACE_BEFORE_WAIT);
+	ret = kevent(kqueue_ev->kqueue_fd, NULL, 0, kevs, MAXEVENTS, timeout);
+	kevent_errno = errno;
+	tevent_trace_point_callback(kqueue_ev->ev, TEVENT_TRACE_AFTER_WAIT);
+
+	if (ret == -1 && kevent_errno == EINTR && kqueue_ev->ev->signal_events) {
+		if (tevent_common_check_signal(kqueue_ev->ev)) {
+			return 0;
+		}
+	}
+
+	if (ret == -1 && kevent_errno != EINTR) {
+		kqueue_panic(kqueue_ev, "kevent() failed");
+		return -1;
+	}
+
+	if (ret == 0 && tvalp) {
+		/* we don't care about a possible delay here */
+		tevent_common_loop_timer_delay(kqueue_ev->ev);
+		return 0;
+	}
+
+	for (i=0;i<ret;i++) {
+		struct tevent_fd *fde = talloc_get_type(kevs[i].udata,
+						        struct tevent_fd);
+		uint16_t flags = 0;
+
+		if (fde == NULL) {
+			kqueue_panic(kqueue_ev, "kevent() gave bad data");
+			return -1;
+		}
+
+		if (kevs[i].flags & EV_EOF) {
+			fde->additional_flags |= KQUEUE_ADDITIONAL_FD_FLAG_GOT_ERROR;
+			/*
+			 * if we only wait for TEVENT_FD_WRITE, we should not
+			 * tell the event handler about it, and remove the
+			 * EVFILT_WRITE filter, as we only report errors when
+			 * waiting for read events, to match the select()
+			 * behavior
+			 */
+			if (!(fde->additional_flags & KQUEUE_ADDITIONAL_FD_FLAG_REPORT_ERROR)) {
+				kqueue_update_fd_event(kqueue_ev, fde);
+				continue;
+			}
+			flags |= TEVENT_FD_READ;
+		}
+		if (kevs[i].filter == EVFILT_READ) {
+			flags |= TEVENT_FD_READ;
+		}
+		if (kevs[i].filter == EVFILT_WRITE) {
+			flags |= TEVENT_FD_WRITE;
+		}
+		if (flags) {
+			fde->handler(kqueue_ev->ev, fde, flags, fde->private_data);
+			break;
+		}
+	}
+
+	return 0;
+}
+
+/*
+  do a single event loop using the events defined in ev
+*/
+static int kqueue_event_loop_once(struct tevent_context *ev, const char *location)
+{
+	struct kqueue_event_context *kqueue_ev = talloc_get_type(ev->additional_data,
+							   struct kqueue_event_context);
+	struct timeval tval;
+
+	if (ev->signal_events &&
+	    tevent_common_check_signal(ev)) {
+		return 0;
+	}
+
+	if (ev->immediate_events &&
+	    tevent_common_loop_immediate(ev)) {
+		return 0;
+	}
+
+	tval = tevent_common_loop_timer_delay(ev);
+	if (tevent_timeval_is_zero(&tval)) {
+		return 0;
+	}
+
+	kqueue_check_reopen(kqueue_ev);
+
+	return kqueue_event_loop(kqueue_ev, &tval);
+}
+
+static const struct tevent_ops kqueue_event_ops = {
+	.context_init		= kqueue_event_context_init,
+	.add_fd			= kqueue_event_add_fd,
+	.set_fd_close_fn	= tevent_common_fd_set_close_fn,
+	.get_fd_flags		= tevent_common_fd_get_flags,
+	.set_fd_flags		= kqueue_event_set_fd_flags,
+	.add_timer		= tevent_common_add_timer,
+	.schedule_immediate	= tevent_common_schedule_immediate,
+	.add_signal		= tevent_common_add_signal,
+	.loop_once		= kqueue_event_loop_once,
+	.loop_wait		= tevent_common_loop_wait,
+};
+
+_PRIVATE_ bool tevent_kqueue_init(void)
+{
+	return tevent_register_backend("kqueue", &kqueue_event_ops);
+}
diff --git a/lib/tevent/wscript b/lib/tevent/wscript
index 684286d..5c3da24 100755
--- a/lib/tevent/wscript
+++ b/lib/tevent/wscript
@@ -44,6 +44,9 @@ def configure(conf):
     if conf.CHECK_FUNCS('epoll_create', headers='sys/epoll.h'):
         conf.DEFINE('HAVE_EPOLL', 1)
 
+    if conf.CHECK_FUNCS('kqueue', headers='sys/types.h sys/event.h sys/time.h'):
+        conf.DEFINE('HAVE_KQUEUE', 1)
+
     conf.env.disable_python = getattr(Options.options, 'disable_python', False)
 
     if not conf.env.disable_python:
@@ -72,6 +75,9 @@ def build(bld):
     if bld.CONFIG_SET('HAVE_EPOLL'):
         SRC += ' tevent_epoll.c'
 
+    if bld.CONFIG_SET('HAVE_KQUEUE'):
+        SRC += ' tevent_kqueue.c'
+
     if bld.env.standalone_tevent:
         bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
         private_library = False
-- 
1.7.9.5


From c477682e4338d43aaee57f41bc1ca7d7a91a4a40 Mon Sep 17 00:00:00 2001
From: Stefan Metzmacher <metze at samba.org>
Date: Sun, 17 Feb 2013 15:35:34 +0100
Subject: [PATCH 2/2] HACK compile kqueue backend

---
 lib/tevent/tevent_internal.h |   42 ++++++++++++++++++++++++++++++++++++++++++
 lib/tevent/wscript           |    1 +
 2 files changed, 43 insertions(+)

diff --git a/lib/tevent/tevent_internal.h b/lib/tevent/tevent_internal.h
index da7bea879..e58dce7 100644
--- a/lib/tevent/tevent_internal.h
+++ b/lib/tevent/tevent_internal.h
@@ -327,6 +327,48 @@ bool tevent_epoll_set_panic_fallback(struct tevent_context *ev,
 #endif
 #ifdef HAVE_KQUEUE
 bool tevent_kqueue_init(void);
+#ifndef HAVE_SYS_EVENT_H
+struct kevent {
+	uintptr_t ident;	     /* identifier for this event */
+	short     filter;	     /* filter for event */
+#define EVFILT_WRITE 1
+#define EVFILT_READ 2
+	u_short   flags;	     /* action flags for kqueue */
+#define EV_ADD		0x0001
+#define EV_ENABLE	0x0002
+#define EV_DISABLE	0x0004
+#define EV_DELETE	0x0008
+#define EV_EOF		0x0010
+	u_int     fflags;	     /* filter flag value */
+	intptr_t  data;	     /* filter data value */
+	void      *udata;	     /* opaque user data identifier */
+};
+
+#define EV_SET(_kev, _ident, _filter, _flags, _fflags, _data, _udata) do { \
+	struct kevent *__kev = _kev; \
+	__kev->ident = _ident; \
+	__kev->filter = _filter; \
+	__kev->flags = _flags; \
+	__kev->fflags = _fflags; \
+	__kev->data = (intptr_t)_data; \
+	__kev->udata = _udata; \
+} while(0)
+
+static inline int kqueue(void)
+{
+	errno = ENOSYS;
+	return -1;
+}
+
+struct timespec;
+static inline int kevent(int kq, const struct kevent *changelist, int nchanges,
+			 struct kevent *eventlist, int nevents,
+			 const struct timespec *timeout)
+{
+	errno = ENOSYS;
+	return -1;
+}
+#endif /* not HAVE_SYS_EVENT_H */
 #endif
 
 
diff --git a/lib/tevent/wscript b/lib/tevent/wscript
index 5c3da24..128090f 100755
--- a/lib/tevent/wscript
+++ b/lib/tevent/wscript
@@ -46,6 +46,7 @@ def configure(conf):
 
     if conf.CHECK_FUNCS('kqueue', headers='sys/types.h sys/event.h sys/time.h'):
         conf.DEFINE('HAVE_KQUEUE', 1)
+    conf.DEFINE('HAVE_KQUEUE', 1) # HACK
 
     conf.env.disable_python = getattr(Options.options, 'disable_python', False)
 
-- 
1.7.9.5
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 261 bytes
Desc: OpenPGP digital signature
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20130217/f76c954d/attachment.pgp>


More information about the samba-technical mailing list