pkgsrc-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

CVS commit: pkgsrc/devel



Module Name:    pkgsrc
Committed By:   nia
Date:           Sun Aug 18 16:05:12 UTC 2019

Modified Files:
        pkgsrc/devel: Makefile
Added Files:
        pkgsrc/devel/wayland: DESCR Makefile PLIST buildlink3.mk distinfo
        pkgsrc/devel/wayland/files: event-loop-kqueue.c
        pkgsrc/devel/wayland/patches: patch-Makefile.am patch-configure.ac
            patch-src_event-loop.c patch-src_wayland-os.c
            patch-src_wayland-os.h patch-src_wayland-server.c
            patch-src_wayland-shm.c patch-tests_client-test.c
            patch-tests_connection-test.c patch-tests_event-loop-test.c
            patch-tests_os-wrappers-test.c patch-tests_queue-test.c
            patch-tests_sanity-test.c patch-tests_test-helpers.c
            patch-tests_test-runner.c

Log Message:
Add devel/wayland.

Wayland is a protocol for a compositor to talk to its clients as
well as a C library implementation of that protocol.

Wayland is intended to be simpler replacement for the X window
system, easier to develop and maintain.


To generate a diff of this commit:
cvs rdiff -u -r1.2897 -r1.2898 pkgsrc/devel/Makefile
cvs rdiff -u -r0 -r1.1 pkgsrc/devel/wayland/DESCR \
    pkgsrc/devel/wayland/Makefile pkgsrc/devel/wayland/PLIST \
    pkgsrc/devel/wayland/buildlink3.mk pkgsrc/devel/wayland/distinfo
cvs rdiff -u -r0 -r1.1 pkgsrc/devel/wayland/files/event-loop-kqueue.c
cvs rdiff -u -r0 -r1.1 pkgsrc/devel/wayland/patches/patch-Makefile.am \
    pkgsrc/devel/wayland/patches/patch-configure.ac \
    pkgsrc/devel/wayland/patches/patch-src_event-loop.c \
    pkgsrc/devel/wayland/patches/patch-src_wayland-os.c \
    pkgsrc/devel/wayland/patches/patch-src_wayland-os.h \
    pkgsrc/devel/wayland/patches/patch-src_wayland-server.c \
    pkgsrc/devel/wayland/patches/patch-src_wayland-shm.c \
    pkgsrc/devel/wayland/patches/patch-tests_client-test.c \
    pkgsrc/devel/wayland/patches/patch-tests_connection-test.c \
    pkgsrc/devel/wayland/patches/patch-tests_event-loop-test.c \
    pkgsrc/devel/wayland/patches/patch-tests_os-wrappers-test.c \
    pkgsrc/devel/wayland/patches/patch-tests_queue-test.c \
    pkgsrc/devel/wayland/patches/patch-tests_sanity-test.c \
    pkgsrc/devel/wayland/patches/patch-tests_test-helpers.c \
    pkgsrc/devel/wayland/patches/patch-tests_test-runner.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/devel/Makefile
diff -u pkgsrc/devel/Makefile:1.2897 pkgsrc/devel/Makefile:1.2898
--- pkgsrc/devel/Makefile:1.2897        Sun Aug 11 03:33:55 2019
+++ pkgsrc/devel/Makefile       Sun Aug 18 16:05:11 2019
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.2897 2019/08/11 03:33:55 markd Exp $
+# $NetBSD: Makefile,v 1.2898 2019/08/18 16:05:11 nia Exp $
 #
 
 COMMENT=       Development utilities
@@ -2826,6 +2826,7 @@ SUBDIR+=  verifast
 SUBDIR+=       visualvm
 SUBDIR+=       vtcl
 SUBDIR+=       waf
+SUBDIR+=       wayland
 SUBDIR+=       woboq_codebrowser
 SUBDIR+=       xa65
 SUBDIR+=       xdelta

Added files:

Index: pkgsrc/devel/wayland/DESCR
diff -u /dev/null pkgsrc/devel/wayland/DESCR:1.1
--- /dev/null   Sun Aug 18 16:05:12 2019
+++ pkgsrc/devel/wayland/DESCR  Sun Aug 18 16:05:12 2019
@@ -0,0 +1,5 @@
+Wayland is a protocol for a compositor to talk to its clients as
+well as a C library implementation of that protocol.
+
+Wayland is intended to be simpler replacement for the X window
+system, easier to develop and maintain.
Index: pkgsrc/devel/wayland/Makefile
diff -u /dev/null pkgsrc/devel/wayland/Makefile:1.1
--- /dev/null   Sun Aug 18 16:05:12 2019
+++ pkgsrc/devel/wayland/Makefile       Sun Aug 18 16:05:12 2019
@@ -0,0 +1,32 @@
+# $NetBSD: Makefile,v 1.1 2019/08/18 16:05:12 nia Exp $
+
+DISTNAME=      wayland-1.17.0
+CATEGORIES=    devel
+MASTER_SITES=  https://wayland.freedesktop.org/releases/
+EXTRACT_SUFX=  .tar.xz
+
+MAINTAINER=    pkgsrc-users%NetBSD.org@localhost
+HOMEPAGE=      https://wayland.freedesktop.org/
+COMMENT=       Display server protocol - development libraries
+LICENSE=       mit
+
+USE_TOOLS+=            autoconf automake autoreconf gmake pkg-config
+USE_LANGUAGES+=                c c++
+GNU_CONFIGURE=         YES
+USE_LIBTOOL=           YES
+CONFIGURE_ARGS+=       --disable-documentation
+
+PKGCONFIG_OVERRIDE+=   src/wayland-client.pc.in
+PKGCONFIG_OVERRIDE+=   src/wayland-cursor.pc.in
+PKGCONFIG_OVERRIDE+=   src/wayland-scanner.pc.in
+PKGCONFIG_OVERRIDE+=   src/wayland-server.pc.in
+
+pre-configure:
+       # https://lists.freedesktop.org/archives/wayland-devel/2019-February/040024.html
+       ${CP} ${FILESDIR}/event-loop-kqueue.c ${WRKSRC}/src
+       cd ${WRKSRC} && autoreconf -fvi
+
+.include "../../devel/libffi/buildlink3.mk"
+.include "../../textproc/expat/buildlink3.mk"
+.include "../../textproc/libxslt/buildlink3.mk"
+.include "../../mk/bsd.pkg.mk"
Index: pkgsrc/devel/wayland/PLIST
diff -u /dev/null pkgsrc/devel/wayland/PLIST:1.1
--- /dev/null   Sun Aug 18 16:05:12 2019
+++ pkgsrc/devel/wayland/PLIST  Sun Aug 18 16:05:12 2019
@@ -0,0 +1,28 @@
+@comment $NetBSD: PLIST,v 1.1 2019/08/18 16:05:12 nia Exp $
+bin/wayland-scanner
+include/wayland-client-core.h
+include/wayland-client-protocol.h
+include/wayland-client.h
+include/wayland-cursor.h
+include/wayland-egl-backend.h
+include/wayland-egl-core.h
+include/wayland-egl.h
+include/wayland-server-core.h
+include/wayland-server-protocol.h
+include/wayland-server.h
+include/wayland-util.h
+include/wayland-version.h
+lib/libwayland-client.la
+lib/libwayland-cursor.la
+lib/libwayland-egl.la
+lib/libwayland-server.la
+lib/pkgconfig/wayland-client.pc
+lib/pkgconfig/wayland-cursor.pc
+lib/pkgconfig/wayland-egl-backend.pc
+lib/pkgconfig/wayland-egl.pc
+lib/pkgconfig/wayland-scanner.pc
+lib/pkgconfig/wayland-server.pc
+share/aclocal/wayland-scanner.m4
+share/wayland/wayland-scanner.mk
+share/wayland/wayland.dtd
+share/wayland/wayland.xml
Index: pkgsrc/devel/wayland/buildlink3.mk
diff -u /dev/null pkgsrc/devel/wayland/buildlink3.mk:1.1
--- /dev/null   Sun Aug 18 16:05:12 2019
+++ pkgsrc/devel/wayland/buildlink3.mk  Sun Aug 18 16:05:12 2019
@@ -0,0 +1,14 @@
+# $NetBSD: buildlink3.mk,v 1.1 2019/08/18 16:05:12 nia Exp $
+
+BUILDLINK_TREE+=       wayland
+
+.if !defined(WAYLAND_BUILDLINK3_MK)
+WAYLAND_BUILDLINK3_MK:=
+
+BUILDLINK_API_DEPENDS.wayland+=        wayland>=1.9.90
+BUILDLINK_PKGSRCDIR.wayland?=  ../../devel/wayland
+
+.include "../../devel/libffi/buildlink3.mk"
+.endif # WAYLAND_BUILDLINK3_MK
+
+BUILDLINK_TREE+=       -wayland
Index: pkgsrc/devel/wayland/distinfo
diff -u /dev/null pkgsrc/devel/wayland/distinfo:1.1
--- /dev/null   Sun Aug 18 16:05:12 2019
+++ pkgsrc/devel/wayland/distinfo       Sun Aug 18 16:05:12 2019
@@ -0,0 +1,21 @@
+$NetBSD: distinfo,v 1.1 2019/08/18 16:05:12 nia Exp $
+
+SHA1 (wayland-1.17.0.tar.xz) = 4d9e08a7a4a07fa37a25d7aa3ef83f08edec0600
+RMD160 (wayland-1.17.0.tar.xz) = 635494fb0f5d9eb1e782f98e08c3e0e26ff44268
+SHA512 (wayland-1.17.0.tar.xz) = c5051aab5ff078b368c196ecfedb33ccd961265bb914845d7ed81de361bb86ae18299575baa6c4eceb0d82cf8b495e8293f31b51d1cbc05d84af0a199ab3f946
+Size (wayland-1.17.0.tar.xz) = 437680 bytes
+SHA1 (patch-Makefile.am) = af2c47eb2e1a4924ea842aeea1d0f00832762ec0
+SHA1 (patch-configure.ac) = df15013a1639d673e5f0a86433a074f6201dbbc4
+SHA1 (patch-src_event-loop.c) = 04d0eed4ba0708518201ec630dab97d52735fb0c
+SHA1 (patch-src_wayland-os.c) = fc1a70d4baf8311afce92a081368104b7a732e27
+SHA1 (patch-src_wayland-os.h) = 2e8fb20d4adfb3666adffe48104205488b4a1c7b
+SHA1 (patch-src_wayland-server.c) = 335de8f5390eb337dfbde26f523162bd44c06baf
+SHA1 (patch-src_wayland-shm.c) = a59ddce3a161bb21fedb04737ff502da608b1da9
+SHA1 (patch-tests_client-test.c) = 6ffe18dfd64176a92f6f795eb757c54a3cf0ad10
+SHA1 (patch-tests_connection-test.c) = af53116c99cbb8d6570bcec66bfd895c1ae01700
+SHA1 (patch-tests_event-loop-test.c) = 79909fdce7b73a7b19c58d3711329f6288fe7204
+SHA1 (patch-tests_os-wrappers-test.c) = 0b45e6952d23589e4991149143331fdb9e0386e1
+SHA1 (patch-tests_queue-test.c) = 3ee8433faa50b033ab880d3c5b6a9846063d6bd6
+SHA1 (patch-tests_sanity-test.c) = 80e06834ccf344fda16a6a8f85e062f2b4a744ec
+SHA1 (patch-tests_test-helpers.c) = 1895c0bdadefdaeaa421e7051b71a297b3a5e2c3
+SHA1 (patch-tests_test-runner.c) = 35d911064c1b65537ef2276797b8041fd6b023f7

Index: pkgsrc/devel/wayland/files/event-loop-kqueue.c
diff -u /dev/null pkgsrc/devel/wayland/files/event-loop-kqueue.c:1.1
--- /dev/null   Sun Aug 18 16:05:12 2019
+++ pkgsrc/devel/wayland/files/event-loop-kqueue.c      Sun Aug 18 16:05:12 2019
@@ -0,0 +1,800 @@
+/*
+ * Copyright © 2008 Kristian Høgsberg
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial
+ * portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "config.h"
+
+#ifdef HAVE_SYS_EVENT_H
+#include <stddef.h>
+#include <stdio.h>
+#include <err.h>
+#include <errno.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <string.h>
+#include <fcntl.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/types.h>
+#include <sys/event.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include "wayland-util.h"
+#include "wayland-private.h"
+#include "wayland-server-core.h"
+#include "wayland-os.h"
+
+/** \cond INTERNAL */
+
+struct wl_event_loop {
+       int event_fd;
+       struct wl_list check_list;
+       struct wl_list idle_list;
+       struct wl_list destroy_list;
+
+       struct wl_signal destroy_signal;
+};
+
+struct wl_event_source_interface {
+       int (*dispatch)(struct wl_event_source *source,
+                       struct kevent *ev);
+};
+
+struct wl_event_source {
+       struct wl_event_source_interface *interface;
+       struct wl_event_loop *loop;
+       struct wl_list link;
+       void *data;
+       int fd;
+};
+
+struct wl_event_source_fd {
+       struct wl_event_source base;
+       wl_event_loop_fd_func_t func;
+       int fd;
+};
+
+/** \endcond */
+
+static int
+wl_event_source_fd_dispatch(struct wl_event_source *source,
+                           struct kevent *ev)
+{
+       struct wl_event_source_fd *fd_source = (struct wl_event_source_fd *) source;
+       uint32_t mask;
+
+       mask = 0;
+       if (ev->filter == EVFILT_READ)
+               mask |= WL_EVENT_READABLE;
+       if (ev->filter == EVFILT_WRITE)
+               mask |= WL_EVENT_WRITABLE;
+       if (ev->flags & EV_EOF)
+               mask |= WL_EVENT_HANGUP;
+       if (ev->flags & EV_ERROR)
+               mask |= WL_EVENT_ERROR;
+
+       return fd_source->func(source->fd, mask, source->data);
+}
+
+struct wl_event_source_interface fd_source_interface = {
+       wl_event_source_fd_dispatch,
+};
+
+static struct wl_event_source *
+add_source(struct wl_event_loop *loop,
+          struct wl_event_source *source, uint32_t mask, void *data)
+{
+       source->loop = loop;
+       source->data = data;
+       wl_list_init(&source->link);
+
+       return source;
+}
+
+/** Create a file descriptor event source
+ *
+ * \param loop The event loop that will process the new source.
+ * \param fd The file descriptor to watch.
+ * \param mask A bitwise-or of which events to watch for: \c WL_EVENT_READABLE,
+ * \c WL_EVENT_WRITABLE.
+ * \param func The file descriptor dispatch function.
+ * \param data User data.
+ * \return A new file descriptor event source.
+ *
+ * The given file descriptor is initially watched for the events given in
+ * \c mask. This can be changed as needed with wl_event_source_fd_update().
+ *
+ * If it is possible that program execution causes the file descriptor to be
+ * read while leaving the data in a buffer without actually processing it,
+ * it may be necessary to register the file descriptor source to be re-checked,
+ * see wl_event_source_check(). This will ensure that the dispatch function
+ * gets called even if the file descriptor is not readable or writable
+ * anymore. This is especially useful with IPC libraries that automatically
+ * buffer incoming data, possibly as a side-effect of other operations.
+ *
+ * \sa wl_event_loop_fd_func_t
+ * \memberof wl_event_source
+ */
+WL_EXPORT struct wl_event_source *
+wl_event_loop_add_fd(struct wl_event_loop *loop,
+                    int fd, uint32_t mask,
+                    wl_event_loop_fd_func_t func,
+                    void *data)
+{
+       struct wl_event_source_fd *source;
+
+       struct kevent events[2];
+       unsigned int num_events = 0;
+
+       source = malloc(sizeof *source);
+       if (source == NULL)
+               return NULL;
+
+       source->base.interface = &fd_source_interface;
+       source->base.fd = wl_os_dupfd_cloexec(fd, 0);
+       source->func = func;
+       source->fd = fd;
+       add_source(loop, &source->base, mask, data);
+
+       if (source->base.fd < 0) {
+               fprintf(stderr, "could not add source\n: %m");
+               free(source);
+               return NULL;
+       }
+
+       if (mask & WL_EVENT_READABLE) {
+               EV_SET(&events[num_events], source->base.fd, EVFILT_READ,
+                     EV_ADD | EV_ENABLE, 0, 0, &source->base);
+               num_events++;
+       }
+
+       if (mask & WL_EVENT_WRITABLE) {
+               EV_SET(&events[num_events], source->base.fd, EVFILT_WRITE,
+                     EV_ADD | EV_ENABLE, 0, 0, &source->base);
+               num_events++;
+       }
+
+       if (kevent(loop->event_fd, events, num_events, NULL, 0, NULL) < 0) {
+               fprintf(stderr, "error adding source %i (%p) to loop %p: %s\n",
+                      source->fd, source, loop, strerror(errno));
+               close(source->base.fd);
+               free(source);
+               return NULL;
+       }
+
+       return &source->base;
+}
+
+/** Update a file descriptor source's event mask
+ *
+ * \param source The file descriptor event source to update.
+ * \param mask The new mask, a bitwise-or of: \c WL_EVENT_READABLE,
+ * \c WL_EVENT_WRITABLE.
+ * \return 0 on success, -1 on failure.
+ *
+ * This changes which events, readable and/or writable, cause the dispatch
+ * callback to be called on.
+ *
+ * File descriptors are usually writable to begin with, so they do not need to
+ * be polled for writable until a write actually fails. When a write fails,
+ * the event mask can be changed to poll for readable and writable, delivering
+ * a dispatch callback when it is possible to write more. Once all data has
+ * been written, the mask can be changed to poll only for readable to avoid
+ * busy-looping on dispatch.
+ *
+ * \sa wl_event_loop_add_fd()
+ * \memberof wl_event_source
+ */
+WL_EXPORT int
+wl_event_source_fd_update(struct wl_event_source *source, uint32_t mask)
+{
+       struct wl_event_loop *loop = source->loop;
+       struct kevent events[2];
+       unsigned int num_events = 0;
+
+       if (mask & WL_EVENT_READABLE) {
+               EV_SET(&events[num_events], source->fd, EVFILT_READ,
+                      EV_ADD | EV_ENABLE, 0, 0, source);
+               num_events++;
+       }
+
+       if (mask & WL_EVENT_WRITABLE) {
+               EV_SET(&events[num_events], source->fd, EVFILT_WRITE,
+                      EV_ADD | EV_ENABLE, 0, 0, source);
+               num_events++;
+       }
+
+       return kevent(loop->event_fd, events, num_events, NULL, 0, NULL);
+}
+
+/** \cond INTERNAL */
+
+struct wl_event_source_timer {
+       struct wl_event_source base;
+       wl_event_loop_timer_func_t func;
+};
+
+/** \endcond */
+
+static int
+wl_event_source_timer_dispatch(struct wl_event_source *source,
+                              struct kevent *ev)
+{
+       struct wl_event_source_timer *timer_source =
+               (struct wl_event_source_timer *) source;
+       uint64_t expires;
+
+       expires = ev->data;    /* XXX unused?! */
+       return timer_source->func(timer_source->base.data);
+}
+
+struct wl_event_source_interface timer_source_interface = {
+       wl_event_source_timer_dispatch,
+};
+
+/** Create a timer event source
+ *
+ * \param loop The event loop that will process the new source.
+ * \param func The timer dispatch function.
+ * \param data User data.
+ * \return A new timer event source.
+ *
+ * The timer is initially disarmed. It needs to be armed with a call to
+ * wl_event_source_timer_update() before it can trigger a dispatch call.
+ *
+ * \sa wl_event_loop_timer_func_t
+ * \memberof wl_event_source
+ */
+WL_EXPORT struct wl_event_source *
+wl_event_loop_add_timer(struct wl_event_loop *loop,
+                       wl_event_loop_timer_func_t func,
+                       void *data)
+{
+       static int next_timer_id = 0;
+       struct wl_event_source_timer *source;
+
+       source = malloc(sizeof *source);
+       if (source == NULL)
+               return NULL;
+       source->base.interface = &timer_source_interface;
+       source->base.fd = next_timer_id++;
+       source->base.loop = loop;
+       source->base.data = data;
+       source->func = func;
+       wl_list_init(&source->base.link);
+
+       return &source->base;
+}
+
+/** Arm or disarm a timer
+ *
+ * \param source The timer event source to modify.
+ * \param ms_delay The timeout in milliseconds.
+ * \return 0 on success, -1 on failure.
+ *
+ * If the timeout is zero, the timer is disarmed.
+ *
+ * If the timeout is non-zero, the timer is set to expire after the given
+ * timeout in milliseconds. When the timer expires, the dispatch function
+ * set with wl_event_loop_add_timer() is called once from
+ * wl_event_loop_dispatch(). If another dispatch is desired after another
+ * expiry, wl_event_source_timer_update() needs to be called again.
+ *
+ * \memberof wl_event_source
+ */
+WL_EXPORT int
+wl_event_source_timer_update(struct wl_event_source *source, int ms_delay)
+{
+       struct kevent ev;
+
+       if (ms_delay == 0) {
+               EV_SET(&ev, source->fd, EVFILT_TIMER, EV_DISABLE, 0,
+                      ms_delay, source);
+       } else {
+               EV_SET(&ev, source->fd, EVFILT_TIMER,
+                      EV_ADD | EV_ENABLE | EV_DISPATCH, 0, ms_delay, source);
+       }
+
+       if (kevent(source->loop->event_fd, &ev, 1, NULL, 0, NULL) < 0) {
+               fprintf(stderr, "could not set kqueue timer: %s",
+                       strerror(errno));
+               return -1;
+       }
+
+       return 0;
+}
+
+/** \cond INTERNAL */
+
+struct wl_event_source_signal {
+       struct wl_event_source base;
+       int signal_number;
+       wl_event_loop_signal_func_t func;
+};
+
+/** \endcond */
+
+static int
+wl_event_source_signal_dispatch(struct wl_event_source *source,
+                               struct kevent *ev)
+{
+       struct wl_event_source_signal *signal_source;
+
+       signal_source = (struct wl_event_source_signal *) source;
+
+       return signal_source->func(signal_source->base.fd,
+                                  signal_source->base.data);
+}
+
+struct wl_event_source_interface signal_source_interface = {
+       wl_event_source_signal_dispatch,
+};
+
+/** Create a POSIX signal event source
+ *
+ * \param loop The event loop that will process the new source.
+ * \param signal_number Number of the signal to watch for.
+ * \param func The signal dispatch function.
+ * \param data User data.
+ * \return A new signal event source.
+ *
+ * This function blocks the normal delivery of the given signal in the calling
+ * thread, and creates a "watch" for it. Signal delivery no longer happens
+ * asynchronously, but by wl_event_loop_dispatch() calling the dispatch
+ * callback function \c func.
+ *
+ * It is the caller's responsibility to ensure that all other threads have
+ * also blocked the signal.
+ *
+ * \sa wl_event_loop_signal_func_t
+ * \memberof wl_event_source
+ */
+WL_EXPORT struct wl_event_source *
+wl_event_loop_add_signal(struct wl_event_loop *loop,
+                       int signal_number,
+                       wl_event_loop_signal_func_t func,
+                       void *data)
+{
+       struct wl_event_source_signal *source;
+       sigset_t mask;
+       struct kevent ev;
+
+       source = malloc(sizeof *source);
+       if (source == NULL)
+               return NULL;
+
+       source->base.interface = &signal_source_interface;
+       source->signal_number = signal_number;
+       source->func = func;
+
+       sigemptyset(&mask);
+       sigaddset(&mask, signal_number);
+       sigprocmask(SIG_BLOCK, &mask, NULL);
+
+       source->base.fd = 0;
+       add_source(loop, &source->base, WL_EVENT_READABLE, data);
+
+       EV_SET(&ev, signal_number, EVFILT_SIGNAL, EV_ADD | EV_ENABLE, 0, 0,
+              source);
+
+       if (kevent(loop->event_fd, &ev, 1, NULL, 0, NULL) < 0) {
+               fprintf(stderr, "error adding signal for %i (%p), %p: %s\n",
+                       signal_number, source, loop, strerror(errno));
+               free(source);
+               return NULL;
+       }
+
+       return &source->base;
+}
+
+/** \cond INTERNAL */
+
+struct wl_event_source_idle {
+       struct wl_event_source base;
+       wl_event_loop_idle_func_t func;
+};
+
+/** \endcond */
+
+struct wl_event_source_interface idle_source_interface = {
+       NULL,
+};
+
+/** Create an idle task
+ *
+ * \param loop The event loop that will process the new task.
+ * \param func The idle task dispatch function.
+ * \param data User data.
+ * \return A new idle task (an event source).
+ *
+ * Idle tasks are dispatched before wl_event_loop_dispatch() goes to sleep.
+ * See wl_event_loop_dispatch() for more details.
+ *
+ * Idle tasks fire once, and are automatically destroyed right after the
+ * callback function has been called.
+ *
+ * An idle task can be cancelled before the callback has been called by
+ * wl_event_source_remove(). Calling wl_event_source_remove() after or from
+ * within the callback results in undefined behaviour.
+ *
+ * \sa wl_event_loop_idle_func_t
+ * \memberof wl_event_source
+ */
+WL_EXPORT struct wl_event_source *
+wl_event_loop_add_idle(struct wl_event_loop *loop,
+                      wl_event_loop_idle_func_t func,
+                      void *data)
+{
+       struct wl_event_source_idle *source;
+
+       source = malloc(sizeof *source);
+       if (source == NULL)
+               return NULL;
+
+       source->base.interface = &idle_source_interface;
+       source->base.loop = loop;
+       source->base.fd = -1;
+
+       source->func = func;
+       source->base.data = data;
+
+       wl_list_insert(loop->idle_list.prev, &source->base.link);
+
+       return &source->base;
+}
+
+/** Mark event source to be re-checked
+ *
+ * \param source The event source to be re-checked.
+ *
+ * This function permanently marks the event source to be re-checked after
+ * the normal dispatch of sources in wl_event_loop_dispatch(). Re-checking
+ * will keep iterating over all such event sources until the dispatch
+ * function for them all returns zero.
+ *
+ * Re-checking is used on sources that may become ready to dispatch as a
+ * side-effect of dispatching themselves or other event sources, including idle
+ * sources. Re-checking ensures all the incoming events have been fully drained
+ * before wl_event_loop_dispatch() returns.
+ *
+ * \memberof wl_event_source
+ */
+WL_EXPORT void
+wl_event_source_check(struct wl_event_source *source)
+{
+       wl_list_insert(source->loop->check_list.prev, &source->link);
+}
+
+/** Remove an event source from its event loop
+ *
+ * \param source The event source to be removed.
+ * \return Zero.
+ *
+ * The event source is removed from the event loop it was created for,
+ * and is effectively destroyed. This invalidates \c source .
+ * The dispatch function of the source will no longer be called through this
+ * source.
+ *
+ * \memberof wl_event_source
+ */
+WL_EXPORT int
+wl_event_source_remove(struct wl_event_source *source)
+{
+       struct wl_event_loop *loop = source->loop;
+       int ret = 0, saved_errno = 0;
+
+       /*
+        * Since BSD doesn't treat all event sources as FDs, we need to
+        * differentiate by source interface.
+        */
+       if (source->interface == &fd_source_interface && source->fd >= 0) {
+               struct kevent ev[2];
+               int _ret[2], _saved_errno[2];
+
+               /*
+                * We haven't stored state about the mask used when adding the
+                * source, so we have to try and remove both READ and WRITE
+                * filters. One may fail, which is OK. Removal of the source has
+                * only failed if _both_ kevent() calls fail. We have to do two
+                * kevent() calls so that we can get independent return values
+                * for the two kevents.
+                */
+               EV_SET(&ev[0], source->fd, EVFILT_READ, EV_DELETE, 0, 0,
+                     source);
+               EV_SET(&ev[1], source->fd, EVFILT_WRITE, EV_DELETE, 0, 0,
+                     source);
+
+               _ret[0] = kevent(loop->event_fd, &ev[0], 1, NULL, 0, NULL);
+               _saved_errno[0] = errno;
+               _ret[1] = kevent(loop->event_fd, &ev[1], 1, NULL, 0, NULL);
+               _saved_errno[1] = errno;
+
+               if (_ret[0] >= _ret[1]) {
+                       ret = _ret[0];
+                       saved_errno = _saved_errno[0];
+               } else {
+                       ret = _ret[1];
+                       saved_errno = _saved_errno[1];
+               }
+
+               close(source->fd);
+       } else if (source->interface == &timer_source_interface) {
+               struct kevent ev;
+
+               EV_SET(&ev, source->fd, EVFILT_TIMER, EV_DELETE, 0, 0, source);
+               ret = kevent(loop->event_fd, &ev, 1, NULL, 0, NULL);
+               saved_errno = errno;
+       } else if (source->interface == &signal_source_interface) {
+               struct kevent ev;
+               int signal_number;
+               struct wl_event_source_signal *_source;
+
+               /* Only one kevent() call needed. */
+               _source = (struct wl_event_source_signal *) source;
+               signal_number = _source->signal_number;
+
+               EV_SET(&ev, signal_number, EVFILT_SIGNAL, EV_DELETE, 0, 0,
+                     source);
+               ret = kevent(loop->event_fd, &ev, 1, NULL, 0, NULL);
+               saved_errno = errno;
+       }
+
+       /* Handle any errors from kevent() calls. */
+       if (ret < 0) {
+               fprintf(stderr,
+                       "error removing event (%i) from kqueue: %s\n",
+                       source->fd, strerror(saved_errno));
+       }
+
+       /* Tidy up the source. */
+       source->fd = -1;
+
+       wl_list_remove(&source->link);
+       wl_list_insert(&loop->destroy_list, &source->link);
+
+       return 0;
+}
+
+static void
+wl_event_loop_process_destroy_list(struct wl_event_loop *loop)
+{
+       struct wl_event_source *source, *next;
+
+       wl_list_for_each_safe(source, next, &loop->destroy_list, link)
+               free(source);
+
+       wl_list_init(&loop->destroy_list);
+}
+
+/** Create a new event loop context
+ *
+ * \return A new event loop context object.
+ *
+ * This creates a new event loop context. Initially this context is empty.
+ * Event sources need to be explicitly added to it.
+ *
+ * Normally the event loop is run by calling wl_event_loop_dispatch() in
+ * a loop until the program terminates. Alternatively, an event loop can be
+ * embedded in another event loop by its file descriptor, see
+ * wl_event_loop_get_fd().
+ *
+ * \memberof wl_event_loop
+ */
+WL_EXPORT struct wl_event_loop *
+wl_event_loop_create(void)
+{
+       struct wl_event_loop *loop;
+
+       loop = malloc(sizeof *loop);
+       if (loop == NULL)
+               return NULL;
+
+       loop->event_fd = wl_os_queue_create_cloexec();
+       if (loop->event_fd < 0) {
+               free(loop);
+               return NULL;
+       }
+       wl_list_init(&loop->check_list);
+       wl_list_init(&loop->idle_list);
+       wl_list_init(&loop->destroy_list);
+
+       wl_signal_init(&loop->destroy_signal);
+
+       return loop;
+}
+
+/** Destroy an event loop context
+ *
+ * \param loop The event loop to be destroyed.
+ *
+ * This emits the event loop destroy signal, closes the event loop file
+ * descriptor, and frees \c loop.
+ *
+ * If the event loop has existing sources, those cannot be safely removed
+ * afterwards. Therefore one must call wl_event_source_remove() on all
+ * event sources before destroying the event loop context.
+ *
+ * \memberof wl_event_loop
+ */
+WL_EXPORT void
+wl_event_loop_destroy(struct wl_event_loop *loop)
+{
+       wl_signal_emit(&loop->destroy_signal, loop);
+
+       wl_event_loop_process_destroy_list(loop);
+       close(loop->event_fd);
+       free(loop);
+}
+
+static bool
+post_dispatch_check(struct wl_event_loop *loop)
+{
+       struct kevent ev;
+       struct wl_event_source *source, *next;
+       bool needs_recheck = false;
+
+       wl_list_for_each_safe(source, next, &loop->check_list, link) {
+               int dispatch_result;
+
+               dispatch_result = source->interface->dispatch(source, &ev);
+               if (dispatch_result < 0) {
+                       wl_log("Source dispatch function returned negative value!");
+                       wl_log("This would previously accidentally suppress a follow-up dispatch");
+               }
+               needs_recheck |= dispatch_result != 0;
+       }
+
+       return needs_recheck;
+}
+
+/** Dispatch the idle sources
+ *
+ * \param loop The event loop whose idle sources are dispatched.
+ *
+ * \sa wl_event_loop_add_idle()
+ * \memberof wl_event_loop
+ */
+WL_EXPORT void
+wl_event_loop_dispatch_idle(struct wl_event_loop *loop)
+{
+       struct wl_event_source_idle *source;
+
+       while (!wl_list_empty(&loop->idle_list)) {
+               source = container_of(loop->idle_list.next,
+                                     struct wl_event_source_idle, base.link);
+               source->func(source->base.data);
+               wl_event_source_remove(&source->base);
+       }
+}
+
+/** Wait for events and dispatch them
+ *
+ * \param loop The event loop whose sources to wait for.
+ * \param timeout The polling timeout in milliseconds.
+ * \return 0 for success, -1 for polling error.
+ *
+ * All the associated event sources are polled. This function blocks until
+ * any event source delivers an event (idle sources excluded), or the timeout
+ * expires. A timeout of -1 disables the timeout, causing the function to block
+ * indefinitely. A timeout of zero causes the poll to always return immediately.
+ *
+ * All idle sources are dispatched before blocking. An idle source is destroyed
+ * when it is dispatched. After blocking, all other ready sources are
+ * dispatched. Then, idle sources are dispatched again, in case the dispatched
+ * events created idle sources. Finally, all sources marked with
+ * wl_event_source_check() are dispatched in a loop until their dispatch
+ * functions all return zero.
+ *
+ * \memberof wl_event_loop
+ */
+WL_EXPORT int
+wl_event_loop_dispatch(struct wl_event_loop *loop, int timeout)
+{
+       struct kevent ev[64];
+       struct wl_event_source *source;
+       int i, count;
+       struct timespec timeout_spec;
+
+       wl_event_loop_dispatch_idle(loop);
+
+       /* timeout is provided in milliseconds */
+       timeout_spec.tv_sec = timeout / 1000;
+       timeout_spec.tv_nsec = (timeout % 1000) * 1000000;
+
+       count = kevent(loop->event_fd, NULL, 0, ev, ARRAY_LENGTH(ev),
+                      (timeout != -1) ? &timeout_spec : NULL);
+       if (count < 0)
+               return -1;
+
+       for (i = 0; i < count; i++) {
+               source = ev[i].udata;
+               if (source->fd != -1) {
+                      source->interface->dispatch(source, &ev[i]);
+               }
+       }
+
+       wl_event_loop_process_destroy_list(loop);
+
+       wl_event_loop_dispatch_idle(loop);
+
+       while (post_dispatch_check(loop));
+
+       return 0;
+}
+
+/** Get the event loop file descriptor
+ *
+ * \param loop The event loop context.
+ * \return The aggregate file descriptor.
+ *
+ * This function returns the aggregate file descriptor, that represents all
+ * the event sources (idle sources excluded) associated with the given event
+ * loop context. When any event source makes an event available, it will be
+ * reflected in the aggregate file descriptor.
+ *
+ * When the aggregate file descriptor delivers an event, one can call
+ * wl_event_loop_dispatch() on the event loop context to dispatch all the
+ * available events.
+ *
+ * \memberof wl_event_loop
+ */
+WL_EXPORT int
+wl_event_loop_get_fd(struct wl_event_loop *loop)
+{
+       return loop->event_fd;
+}
+
+/** Register a destroy listener for an event loop context
+ *
+ * \param loop The event loop context whose destruction to listen for.
+ * \param listener The listener with the callback to be called.
+ *
+ * \sa wl_listener
+ * \memberof wl_event_loop
+ */
+WL_EXPORT void
+wl_event_loop_add_destroy_listener(struct wl_event_loop *loop,
+                                  struct wl_listener *listener)
+{
+       wl_signal_add(&loop->destroy_signal, listener);
+}
+
+/** Get the listener struct for the specified callback
+ *
+ * \param loop The event loop context to inspect.
+ * \param notify The destroy callback to find.
+ * \return The wl_listener registered to the event loop context with
+ * the given callback pointer.
+ *
+ * \memberof wl_event_loop
+ */
+WL_EXPORT struct wl_listener *
+wl_event_loop_get_destroy_listener(struct wl_event_loop *loop,
+                                  wl_notify_func_t notify)
+{
+       return wl_signal_get(&loop->destroy_signal, notify);
+}
+#endif

Index: pkgsrc/devel/wayland/patches/patch-Makefile.am
diff -u /dev/null pkgsrc/devel/wayland/patches/patch-Makefile.am:1.1
--- /dev/null   Sun Aug 18 16:05:12 2019
+++ pkgsrc/devel/wayland/patches/patch-Makefile.am      Sun Aug 18 16:05:12 2019
@@ -0,0 +1,25 @@
+$NetBSD: patch-Makefile.am,v 1.1 2019/08/18 16:05:12 nia Exp $
+
+https://lists.freedesktop.org/archives/wayland-devel/2019-February/040024.html
+
+--- Makefile.am.orig   2019-03-21 00:55:25.000000000 +0000
++++ Makefile.am
+@@ -76,7 +76,8 @@ libwayland_server_la_LDFLAGS = -version-
+ libwayland_server_la_SOURCES =                        \
+       src/wayland-server.c                    \
+       src/wayland-shm.c                       \
+-      src/event-loop.c
++      src/event-loop.c                        \
++      src/event-loop-kqueue.c 
+ 
+ nodist_libwayland_server_la_SOURCES =         \
+       protocol/wayland-server-protocol.h      \
+@@ -227,7 +228,7 @@ libtest_runner_la_LIBADD =                 \
+       libwayland-client.la                    \
+       libwayland-server.la                    \
+       libtest-helpers.la                      \
+-      -lrt -ldl $(FFI_LIBS)
++      -lrt $(DL_LIBS) $(FFI_LIBS)
+ 
+ array_test_SOURCES = tests/array-test.c
+ array_test_LDADD = libtest-runner.la
Index: pkgsrc/devel/wayland/patches/patch-configure.ac
diff -u /dev/null pkgsrc/devel/wayland/patches/patch-configure.ac:1.1
--- /dev/null   Sun Aug 18 16:05:12 2019
+++ pkgsrc/devel/wayland/patches/patch-configure.ac     Sun Aug 18 16:05:12 2019
@@ -0,0 +1,67 @@
+$NetBSD: patch-configure.ac,v 1.1 2019/08/18 16:05:12 nia Exp $
+
+BSD support from FreeBSD
+
+https://lists.freedesktop.org/archives/wayland-devel/2019-February/040024.html
+
+--- configure.ac.orig  2019-03-21 00:55:25.000000000 +0000
++++ configure.ac
+@@ -65,6 +65,28 @@ AC_SUBST(GCC_CFLAGS)
+ AC_CHECK_HEADERS([sys/prctl.h])
+ AC_CHECK_FUNCS([accept4 mkostemp posix_fallocate prctl])
+ 
++
++AC_CHECK_HEADERS([sys/epoll.h sys/event.h])
++if test "x$ac_cv_header_sys_epoll_h" != "xyes" && test "x$ac_cv_header_sys_event_h" != "xyes"; then
++      AC_MSG_ERROR([Can't find sys/epoll.h or sys/event.h. Please ensure either epoll or kqueue is available.])
++fi
++
++AC_CHECK_HEADERS([sys/signalfd.h sys/timerfd.h])
++
++# Credential support on FreeBSD
++AC_CHECK_HEADERS([sys/ucred.h])
++
++# dlopen()
++AC_CHECK_LIB([dl], [dlsym], [DL_LIBS=-ldl])
++AC_SUBST([DL_LIBS])
++
++# Defines __FreeBSD__ if we're on FreeBSD
++AC_CHECK_HEADERS([sys/param.h])
++
++# waitid() and signal.h are needed for the test suite.
++AC_CHECK_FUNCS([waitid])
++AC_CHECK_HEADERS([signal.h])
++
+ AC_ARG_ENABLE([libraries],
+             [AC_HELP_STRING([--disable-libraries],
+                             [Disable compilation of wayland libraries])],
+@@ -100,17 +122,23 @@ AC_SUBST([ICONDIR])
+ 
+ if test "x$enable_libraries" = "xyes"; then
+       PKG_CHECK_MODULES(FFI, [libffi])
+-      AC_CHECK_DECL(SFD_CLOEXEC,[],
+-                    [AC_MSG_ERROR("SFD_CLOEXEC is needed to compile wayland libraries")],
+-                    [[#include <sys/signalfd.h>]])
+-      AC_CHECK_DECL(TFD_CLOEXEC,[],
+-                    [AC_MSG_ERROR("TFD_CLOEXEC is needed to compile wayland libraries")],
+-                    [[#include <sys/timerfd.h>]])
++dnl convert SFD_CLOEXEC and TFD_CLOEXEC to warning while figuring out how to do this.
++      if test "x$ac_cv_header_sys_epoll_h" = "xyes"; then
++              AC_CHECK_DECL(SFD_CLOEXEC,[],
++                            [AC_MSG_WARN("SFD_CLOEXEC is needed to compile wayland libraries")],
++                            [[#include <sys/signalfd.h>]])
++              AC_CHECK_DECL(TFD_CLOEXEC,[],
++                            [AC_MSG_WARN("TFD_CLOEXEC is needed to compile wayland libraries")],
++                            [[#include <sys/timerfd.h>]])
++      fi
+       AC_CHECK_DECL(CLOCK_MONOTONIC,[],
+                     [AC_MSG_ERROR("CLOCK_MONOTONIC is needed to compile wayland libraries")],
+                     [[#include <time.h>]])
+ fi
+ 
++EPOLLSHIM_LIBS="-lepoll-shim"
++AC_SUBST(EPOLLSHIM_LIBS)
++
+ PKG_CHECK_MODULES(EXPAT, [expat])
+ 
+ AM_CONDITIONAL([DTD_VALIDATION], [test "x$enable_dtd_validation" = "xyes"])
Index: pkgsrc/devel/wayland/patches/patch-src_event-loop.c
diff -u /dev/null pkgsrc/devel/wayland/patches/patch-src_event-loop.c:1.1
--- /dev/null   Sun Aug 18 16:05:12 2019
+++ pkgsrc/devel/wayland/patches/patch-src_event-loop.c Sun Aug 18 16:05:12 2019
@@ -0,0 +1,32 @@
+$NetBSD: patch-src_event-loop.c,v 1.1 2019/08/18 16:05:12 nia Exp $
+
+https://lists.freedesktop.org/archives/wayland-devel/2019-February/040024.html
+
+--- src/event-loop.c.orig      2019-03-21 00:55:25.000000000 +0000
++++ src/event-loop.c
+@@ -22,7 +22,8 @@
+  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+  * SOFTWARE.
+  */
+-
++#include "config.h"
++#ifdef HAVE_SYS_EPOLL_H
+ #include <stddef.h>
+ #include <stdio.h>
+ #include <errno.h>
+@@ -35,9 +36,9 @@
+ #include <sys/socket.h>
+ #include <sys/un.h>
+ #include <sys/epoll.h>
++#include <unistd.h>
+ #include <sys/signalfd.h>
+ #include <sys/timerfd.h>
+-#include <unistd.h>
+ #include "wayland-util.h"
+ #include "wayland-private.h"
+ #include "wayland-server-core.h"
+@@ -702,3 +703,4 @@ wl_event_loop_get_destroy_listener(struc
+ {
+       return wl_signal_get(&loop->destroy_signal, notify);
+ }
++#endif /* HAVE_SYS_EPOLL_H */
Index: pkgsrc/devel/wayland/patches/patch-src_wayland-os.c
diff -u /dev/null pkgsrc/devel/wayland/patches/patch-src_wayland-os.c:1.1
--- /dev/null   Sun Aug 18 16:05:12 2019
+++ pkgsrc/devel/wayland/patches/patch-src_wayland-os.c Sun Aug 18 16:05:12 2019
@@ -0,0 +1,120 @@
+$NetBSD: patch-src_wayland-os.c,v 1.1 2019/08/18 16:05:12 nia Exp $
+
+BSD support from FreeBSD
+
+https://lists.freedesktop.org/archives/wayland-devel/2019-February/040024.html
+
+--- src/wayland-os.c.orig      2019-03-21 00:55:25.000000000 +0000
++++ src/wayland-os.c
+@@ -25,14 +25,20 @@
+ 
+ #define _GNU_SOURCE
+ 
++#include "../config.h"
++
+ #include <sys/types.h>
+ #include <sys/socket.h>
+ #include <unistd.h>
+ #include <fcntl.h>
+ #include <errno.h>
++#ifdef HAVE_SYS_EPOLL_H
+ #include <sys/epoll.h>
++#endif
++#ifdef HAVE_SYS_EVENT_H
++#include <sys/event.h>
++#endif
+ 
+-#include "../config.h"
+ #include "wayland-os.h"
+ 
+ static int
+@@ -62,26 +68,50 @@ wl_os_socket_cloexec(int domain, int typ
+ {
+       int fd;
+ 
++#ifdef SOCK_CLOEXEC
+       fd = socket(domain, type | SOCK_CLOEXEC, protocol);
+       if (fd >= 0)
+               return fd;
+       if (errno != EINVAL)
+               return -1;
++#endif
+ 
+       fd = socket(domain, type, protocol);
+       return set_cloexec_or_close(fd);
+ }
+ 
+ int
++wl_os_socketpair_cloexec(int domain, int type, int protocol, int sv[2])
++{
++       int retval;
++
++#ifdef SOCK_CLOEXEC
++       retval = socketpair(domain, type | SOCK_CLOEXEC, protocol, sv);
++       if (retval >= 0)
++               return retval;
++       if (errno != EINVAL)
++               return -1;
++#endif
++
++       retval = socketpair(domain, type, protocol, sv);
++       if (set_cloexec_or_close(sv[0]) < 0 || set_cloexec_or_close(sv[1]) < 0)
++               retval = -1;
++
++       return retval;
++}
++
++int
+ wl_os_dupfd_cloexec(int fd, long minfd)
+ {
+       int newfd;
+ 
++#ifdef F_DUPFD_CLOEXEC
+       newfd = fcntl(fd, F_DUPFD_CLOEXEC, minfd);
+       if (newfd >= 0)
+               return newfd;
+       if (errno != EINVAL)
+               return -1;
++#endif
+ 
+       newfd = fcntl(fd, F_DUPFD, minfd);
+       return set_cloexec_or_close(newfd);
+@@ -123,17 +153,20 @@ wl_os_recvmsg_cloexec(int sockfd, struct
+ {
+       ssize_t len;
+ 
++#ifdef MSG_CMSG_CLOEXEC
+       len = recvmsg(sockfd, msg, flags | MSG_CMSG_CLOEXEC);
+       if (len >= 0)
+               return len;
+       if (errno != EINVAL)
+               return -1;
++#endif
+ 
+       return recvmsg_cloexec_fallback(sockfd, msg, flags);
+ }
+ 
++#ifdef HAVE_SYS_EPOLL_H
+ int
+-wl_os_epoll_create_cloexec(void)
++wl_os_queue_create_cloexec(void)
+ {
+       int fd;
+ 
+@@ -148,6 +181,16 @@ wl_os_epoll_create_cloexec(void)
+       fd = epoll_create(1);
+       return set_cloexec_or_close(fd);
+ }
++#elif defined(HAVE_SYS_EVENT_H)
++int
++wl_os_queue_create_cloexec(void)
++{
++      int fd;
++
++      fd = kqueue();
++      return set_cloexec_or_close(fd);
++}
++#endif
+ 
+ int
+ wl_os_accept_cloexec(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
Index: pkgsrc/devel/wayland/patches/patch-src_wayland-os.h
diff -u /dev/null pkgsrc/devel/wayland/patches/patch-src_wayland-os.h:1.1
--- /dev/null   Sun Aug 18 16:05:12 2019
+++ pkgsrc/devel/wayland/patches/patch-src_wayland-os.h Sun Aug 18 16:05:12 2019
@@ -0,0 +1,33 @@
+$NetBSD: patch-src_wayland-os.h,v 1.1 2019/08/18 16:05:12 nia Exp $
+
+BSD support from FreeBSD
+
+https://lists.freedesktop.org/archives/wayland-devel/2019-February/040024.html
+
+--- src/wayland-os.h.orig      2019-03-21 00:55:25.000000000 +0000
++++ src/wayland-os.h
+@@ -26,17 +26,23 @@
+ #ifndef WAYLAND_OS_H
+ #define WAYLAND_OS_H
+ 
++#include "../config.h"
++
+ int
+ wl_os_socket_cloexec(int domain, int type, int protocol);
+ 
+ int
++wl_os_socketpair_cloexec(int domain, int type, int protocol, int sv[2]);
++
++int
+ wl_os_dupfd_cloexec(int fd, long minfd);
+ 
+ ssize_t
+ wl_os_recvmsg_cloexec(int sockfd, struct msghdr *msg, int flags);
+ 
++
+ int
+-wl_os_epoll_create_cloexec(void);
++wl_os_queue_create_cloexec(void);
+ 
+ int
+ wl_os_accept_cloexec(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
Index: pkgsrc/devel/wayland/patches/patch-src_wayland-server.c
diff -u /dev/null pkgsrc/devel/wayland/patches/patch-src_wayland-server.c:1.1
--- /dev/null   Sun Aug 18 16:05:12 2019
+++ pkgsrc/devel/wayland/patches/patch-src_wayland-server.c     Sun Aug 18 16:05:12 2019
@@ -0,0 +1,100 @@
+$NetBSD: patch-src_wayland-server.c,v 1.1 2019/08/18 16:05:12 nia Exp $
+
+BSD support from FreeBSD
+
+--- src/wayland-server.c.orig  2019-03-21 00:55:25.000000000 +0000
++++ src/wayland-server.c
+@@ -25,6 +25,8 @@
+ 
+ #define _GNU_SOURCE
+ 
++#include "../config.h"
++
+ #include <stdlib.h>
+ #include <stdint.h>
+ #include <stddef.h>
+@@ -43,6 +45,11 @@
+ #include <sys/file.h>
+ #include <sys/stat.h>
+ 
++#ifdef HAVE_SYS_UCRED_H
++#include <sys/types.h>
++#include <sys/ucred.h>
++#endif
++
+ #include "wayland-util.h"
+ #include "wayland-private.h"
+ #include "wayland-server.h"
+@@ -77,7 +84,17 @@ struct wl_client {
+       struct wl_list link;
+       struct wl_map objects;
+       struct wl_priv_signal destroy_signal;
++#ifdef HAVE_SYS_UCRED_H
++#ifdef __NetBSD__
++      struct uucred xucred;
++#else
++      /* FreeBSD */
++      struct xucred xucred;
++#endif
++#else
++      /* Linux */
+       struct ucred ucred;
++#endif
+       int error;
+       struct wl_priv_signal resource_created_signal;
+ };
+@@ -312,7 +329,8 @@ wl_resource_post_error(struct wl_resourc
+ static void
+ destroy_client_with_error(struct wl_client *client, const char *reason)
+ {
+-      wl_log("%s (pid %u)\n", reason, client->ucred.pid);
++      wl_log("Destroying with error: %s\n", reason);
++      //wl_log("%s (pid %u)\n", reason, client->ucred.pid);
+       wl_client_destroy(client);
+ }
+ 
+@@ -526,10 +544,20 @@ wl_client_create(struct wl_display *disp
+       if (!client->source)
+               goto err_client;
+ 
++#if defined(SO_PEERCRED)
++      /* Linux */
+       len = sizeof client->ucred;
+       if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED,
+                      &client->ucred, &len) < 0)
+               goto err_source;
++#elif defined(LOCAL_PEERCRED)
++      /* FreeBSD */
++      len = sizeof client->xucred;
++      if (getsockopt(fd, SOL_SOCKET, LOCAL_PEERCRED,
++                     &client->xucred, &len) < 0 ||
++                     client->xucred.cr_version != XUCRED_VERSION)
++              goto err_source;
++#endif
+ 
+       client->connection = wl_connection_create(fd);
+       if (client->connection == NULL)
+@@ -583,12 +611,23 @@ WL_EXPORT void
+ wl_client_get_credentials(struct wl_client *client,
+                         pid_t *pid, uid_t *uid, gid_t *gid)
+ {
++#ifdef HAVE_SYS_UCRED_H
++      /* FreeBSD */
++      if (pid)
++              *pid = 0; /* FIXME: not defined on FreeBSD */
++      if (uid)
++              *uid = client->xucred.cr_uid;
++      if (gid)
++              *gid = client->xucred.cr_gid;
++#else
++      /* Linux */
+       if (pid)
+               *pid = client->ucred.pid;
+       if (uid)
+               *uid = client->ucred.uid;
+       if (gid)
+               *gid = client->ucred.gid;
++#endif
+ }
+ 
+ /** Get the file descriptor for the client
Index: pkgsrc/devel/wayland/patches/patch-src_wayland-shm.c
diff -u /dev/null pkgsrc/devel/wayland/patches/patch-src_wayland-shm.c:1.1
--- /dev/null   Sun Aug 18 16:05:12 2019
+++ pkgsrc/devel/wayland/patches/patch-src_wayland-shm.c        Sun Aug 18 16:05:12 2019
@@ -0,0 +1,151 @@
+$NetBSD: patch-src_wayland-shm.c,v 1.1 2019/08/18 16:05:12 nia Exp $
+
+BSD support from FreeBSD
+
+--- src/wayland-shm.c.orig     2019-03-21 00:55:25.000000000 +0000
++++ src/wayland-shm.c
+@@ -30,6 +30,8 @@
+ 
+ #define _GNU_SOURCE
+ 
++#include "../config.h"
++
+ #include <stdbool.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+@@ -59,6 +61,9 @@ struct wl_shm_pool {
+       char *data;
+       int32_t size;
+       int32_t new_size;
++#ifdef HAVE_SYS_UCRED_H
++      int fd;
++#endif
+ };
+ 
+ struct wl_shm_buffer {
+@@ -76,15 +81,24 @@ struct wl_shm_sigbus_data {
+       int fallback_mapping_used;
+ };
+ 
++static void *mremap_compat_maymove(void *, size_t, size_t, int, int, int);
++
+ static void
+ shm_pool_finish_resize(struct wl_shm_pool *pool)
+ {
+       void *data;
++      int fd = -1;
+ 
+       if (pool->size == pool->new_size)
+               return;
+ 
+-      data = mremap(pool->data, pool->size, pool->new_size, MREMAP_MAYMOVE);
++#ifdef HAVE_SYS_UCRED_H
++      fd = pool->fd;
++#endif
++
++      data = mremap_compat_maymove(pool->data, pool->size, pool->new_size,
++                                   PROT_READ | PROT_WRITE, MAP_SHARED, fd);
++
+       if (data == MAP_FAILED) {
+               wl_resource_post_error(pool->resource,
+                                      WL_SHM_ERROR_INVALID_FD,
+@@ -110,6 +124,10 @@ shm_pool_unref(struct wl_shm_pool *pool,
+       if (pool->internal_refcount + pool->external_refcount)
+               return;
+ 
++#ifdef HAVE_SYS_UCRED_H
++      close(pool->fd);
++#endif
++
+       munmap(pool->data, pool->size);
+       free(pool);
+ }
+@@ -223,6 +241,73 @@ shm_pool_destroy(struct wl_client *clien
+       wl_resource_destroy(resource);
+ }
+ 
++#ifdef HAVE_MREMAP
++static void *
++mremap_compat_maymove(void *old_address, size_t old_size, size_t new_size,
++                    int old_prot, int old_flags, int old_fd)
++{
++      return mremap(old_address, old_size, new_size, MREMAP_MAYMOVE);
++}
++#else
++static void *
++mremap_compat_maymove(void *old_address, size_t old_size, size_t new_size,
++                    int old_prot, int old_flags, int old_fd)
++{
++      /* FreeBSD doesn't support mremap() yet, so we have to emulate it.
++       * This assumes MREMAP_MAYMOVE is the only flag in use. */
++      if (new_size == old_size) {
++              return old_address;
++      } else if (new_size < old_size) {
++              /* Shrinking: munmap() the spare region. */
++              munmap(old_address + old_size, new_size - old_size);
++              return old_address;
++      } else {
++              void *ret;
++
++              /* Growing. Try and mmap() the extra region at the end of
++               * our existing allocation. If that gets mapped in the
++               * wrong place, fall back to mmap()ing an entirely new
++               * region of new_size and copying the data across. */
++              ret = mmap(old_address + old_size, new_size - old_size,
++                         old_prot, old_flags, old_fd, 0);
++
++/* FIXME TODO: msync() before munmap()? */
++              if (ret == MAP_FAILED) {
++                      /* Total failure! */
++                      return ret;
++              } else if (ret == old_address + old_size) {
++                      /* Success. */
++                      return old_address;
++              } else if (ret != old_address + old_size) {
++                      /* Partial failure. Fall back to mapping an
++                       * entirely new region. Unmap the region we
++                       * just mapped first. */
++                      munmap(ret, new_size - old_size);
++
++                      /* Map an entirely new region. */
++                      ret = mmap(NULL, new_size,
++                                 old_prot, old_flags, old_fd, 0);
++                      if (ret == MAP_FAILED) {
++                              /* Total failure! */
++                              return ret;
++                      }
++
++                      /* Copy the old data across. Implicit assumption
++                       * that the old and new regions don't overlap. */
++                      memcpy(ret, old_address, old_size);
++
++                      /* Unmap the old region. */
++                      munmap(old_address, old_size);
++
++                      return ret;
++              }
++      }
++
++      /* Unreachable. */
++      return MAP_FAILED;
++}
++#endif
++
+ static void
+ shm_pool_resize(struct wl_client *client, struct wl_resource *resource,
+               int32_t size)
+@@ -284,7 +369,14 @@ shm_create_pool(struct wl_client *client
+                                      "failed mmap fd %d: %m", fd);
+               goto err_free;
+       }
++
++#ifdef HAVE_SYS_UCRED_H
++      /* We need to keep the FD around on FreeBSD so we can implement
++       * mremap(). See: mremap_compat_maymove(). */
++      pool->fd = fd;
++#else
+       close(fd);
++#endif
+ 
+       pool->resource =
+               wl_resource_create(client, &wl_shm_pool_interface, 1, id);
Index: pkgsrc/devel/wayland/patches/patch-tests_client-test.c
diff -u /dev/null pkgsrc/devel/wayland/patches/patch-tests_client-test.c:1.1
--- /dev/null   Sun Aug 18 16:05:12 2019
+++ pkgsrc/devel/wayland/patches/patch-tests_client-test.c      Sun Aug 18 16:05:12 2019
@@ -0,0 +1,23 @@
+$NetBSD: patch-tests_client-test.c,v 1.1 2019/08/18 16:05:12 nia Exp $
+
+BSD support from FreeBSD
+
+--- tests/client-test.c.orig   2015-07-06 19:38:51 UTC
++++ tests/client-test.c
+@@ -34,6 +34,7 @@
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ 
++#include "wayland-os.h"
+ #include "wayland-private.h"
+ #include "wayland-server.h"
+ #include "test-runner.h"
+@@ -59,7 +60,7 @@ TEST(client_destroy_listener)
+       struct client_destroy_listener a, b;
+       int s[2];
+ 
+-      assert(socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, s) == 0);
++      assert(wl_os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, s) == 0);
+       display = wl_display_create();
+       assert(display);
+       client = wl_client_create(display, s[0]);
Index: pkgsrc/devel/wayland/patches/patch-tests_connection-test.c
diff -u /dev/null pkgsrc/devel/wayland/patches/patch-tests_connection-test.c:1.1
--- /dev/null   Sun Aug 18 16:05:12 2019
+++ pkgsrc/devel/wayland/patches/patch-tests_connection-test.c  Sun Aug 18 16:05:12 2019
@@ -0,0 +1,33 @@
+$NetBSD: patch-tests_connection-test.c,v 1.1 2019/08/18 16:05:12 nia Exp $
+
+BSD support from FreeBSD
+
+--- tests/connection-test.c.orig       2017-02-07 22:59:06 UTC
++++ tests/connection-test.c
+@@ -37,6 +37,7 @@
+ #include <sys/stat.h>
+ #include <poll.h>
+ 
++#include "wayland-os.h"
+ #include "wayland-private.h"
+ #include "test-runner.h"
+ #include "test-compositor.h"
+@@ -48,7 +49,7 @@ setup(int *s)
+ {
+       struct wl_connection *connection;
+ 
+-      assert(socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, s) == 0);
++      assert(wl_os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, s) == 0);
+ 
+       connection = wl_connection_create(s[0]);
+       assert(connection);
+@@ -181,8 +182,7 @@ struct marshal_data {
+ static void
+ setup_marshal_data(struct marshal_data *data)
+ {
+-      assert(socketpair(AF_UNIX,
+-                        SOCK_STREAM | SOCK_CLOEXEC, 0, data->s) == 0);
++      assert(wl_os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, data->s) == 0);
+       data->read_connection = wl_connection_create(data->s[0]);
+       assert(data->read_connection);
+       data->write_connection = wl_connection_create(data->s[1]);
Index: pkgsrc/devel/wayland/patches/patch-tests_event-loop-test.c
diff -u /dev/null pkgsrc/devel/wayland/patches/patch-tests_event-loop-test.c:1.1
--- /dev/null   Sun Aug 18 16:05:12 2019
+++ pkgsrc/devel/wayland/patches/patch-tests_event-loop-test.c  Sun Aug 18 16:05:12 2019
@@ -0,0 +1,44 @@
+$NetBSD: patch-tests_event-loop-test.c,v 1.1 2019/08/18 16:05:12 nia Exp $
+
+BSD support from FreeBSD
+
+--- tests/event-loop-test.c.orig       2019-03-21 00:55:25.000000000 +0000
++++ tests/event-loop-test.c
+@@ -167,10 +167,10 @@ TEST(event_loop_signal)
+                                         signal_callback, &got_it);
+       assert(source);
+ 
+-      wl_event_loop_dispatch(loop, 0);
++      assert(wl_event_loop_dispatch(loop, 0) == 0);
+       assert(!got_it);
+-      kill(getpid(), SIGUSR1);
+-      wl_event_loop_dispatch(loop, 0);
++      assert(kill(getpid(), SIGUSR1) == 0);
++      assert(wl_event_loop_dispatch(loop, 0) == 0);
+       assert(got_it == 1);
+ 
+       wl_event_source_remove(source);
+@@ -234,12 +234,20 @@ TEST(event_loop_timer)
+ 
+       source = wl_event_loop_add_timer(loop, timer_callback, &got_it);
+       assert(source);
+-      wl_event_source_timer_update(source, 10);
+-      wl_event_loop_dispatch(loop, 0);
++      assert(wl_event_source_timer_update(source, 10) == 0);
++      assert(wl_event_loop_dispatch(loop, 0) == 0);
+       assert(!got_it);
+-      wl_event_loop_dispatch(loop, 20);
++      /* FreeBSD has a bug where it converts ms_timeout to ticks; it always adds 1 to the tick count.
++      * Consequently, we need to grossly overcompensate here.
++      * See: http://unix.derkeiler.com/Mailing-Lists/FreeBSD/hackers/2012-07/msg00319.html */
++      assert(wl_event_loop_dispatch(loop, 50) == 0);
+       assert(got_it == 1);
+ 
++      /* Check it doesn't fire again. */
++      got_it = 0;
++      assert(wl_event_loop_dispatch(loop, 20) == 0);
++      assert(!got_it);
++
+       wl_event_source_remove(source);
+       wl_event_loop_destroy(loop);
+ }
Index: pkgsrc/devel/wayland/patches/patch-tests_os-wrappers-test.c
diff -u /dev/null pkgsrc/devel/wayland/patches/patch-tests_os-wrappers-test.c:1.1
--- /dev/null   Sun Aug 18 16:05:12 2019
+++ pkgsrc/devel/wayland/patches/patch-tests_os-wrappers-test.c Sun Aug 18 16:05:12 2019
@@ -0,0 +1,203 @@
+$NetBSD: patch-tests_os-wrappers-test.c,v 1.1 2019/08/18 16:05:12 nia Exp $
+
+BSD support from FreeBSD
+
+https://lists.freedesktop.org/archives/wayland-devel/2019-February/040024.html
+
+--- tests/os-wrappers-test.c.orig      2019-03-21 00:55:25.000000000 +0000
++++ tests/os-wrappers-test.c
+@@ -26,6 +26,8 @@
+ 
+ #define _GNU_SOURCE
+ 
++#include "../config.h"
++
+ #include <stdlib.h>
+ #include <stdint.h>
+ #include <assert.h>
+@@ -38,7 +40,12 @@
+ #include <stdarg.h>
+ #include <fcntl.h>
+ #include <stdio.h>
++
++#ifdef HAVE_SYS_EPOLL_H
+ #include <sys/epoll.h>
++#elif defined(HAVE_SYS_EVENT_H)
++#include <sys/event.h>
++#endif
+ 
+ #include "wayland-private.h"
+ #include "test-runner.h"
+@@ -55,8 +62,13 @@ static int wrapped_calls_fcntl;
+ static ssize_t (*real_recvmsg)(int, struct msghdr *, int);
+ static int wrapped_calls_recvmsg;
+ 
++#ifdef HAVE_SYS_EPOLL_H
+ static int (*real_epoll_create1)(int);
+ static int wrapped_calls_epoll_create1;
++#elif defined(HAVE_SYS_EVENT_H)
++static int (*real_kqueue)(void);
++static int wrapped_calls_kqueue;
++#endif
+ 
+ static void
+ init_fallbacks(int do_fallbacks)
+@@ -65,7 +77,11 @@ init_fallbacks(int do_fallbacks)
+       real_socket = dlsym(RTLD_NEXT, "socket");
+       real_fcntl = dlsym(RTLD_NEXT, "fcntl");
+       real_recvmsg = dlsym(RTLD_NEXT, "recvmsg");
++#ifdef HAVE_SYS_EPOLL_H
+       real_epoll_create1 = dlsym(RTLD_NEXT, "epoll_create1");
++#elif defined(HAVE_SYS_EVENT_H)
++      real_kqueue = dlsym(RTLD_NEXT, "kqueue");
++#endif
+ }
+ 
+ __attribute__ ((visibility("default"))) int
+@@ -73,10 +89,12 @@ socket(int domain, int type, int protoco
+ {
+       wrapped_calls_socket++;
+ 
++#ifdef SOCK_CLOEXEC
+       if (fall_back && (type & SOCK_CLOEXEC)) {
+               errno = EINVAL;
+               return -1;
+       }
++#endif
+ 
+       return real_socket(domain, type, protocol);
+ }
+@@ -89,10 +107,12 @@ fcntl(int fd, int cmd, ...)
+ 
+       wrapped_calls_fcntl++;
+ 
++#ifdef F_DUPFD_CLOEXEC
+       if (fall_back && (cmd == F_DUPFD_CLOEXEC)) {
+               errno = EINVAL;
+               return -1;
+       }
++#endif
+ 
+       va_start(ap, cmd);
+       arg = va_arg(ap, void*);
+@@ -106,14 +126,17 @@ recvmsg(int sockfd, struct msghdr *msg, 
+ {
+       wrapped_calls_recvmsg++;
+ 
++#ifdef MSG_CMSG_CLOEXEC
+       if (fall_back && (flags & MSG_CMSG_CLOEXEC)) {
+               errno = EINVAL;
+               return -1;
+       }
++#endif
+ 
+       return real_recvmsg(sockfd, msg, flags);
+ }
+ 
++#ifdef HAVE_SYS_EPOLL_H
+ __attribute__ ((visibility("default"))) int
+ epoll_create1(int flags)
+ {
+@@ -127,6 +150,21 @@ epoll_create1(int flags)
+ 
+       return real_epoll_create1(flags);
+ }
++#elif defined(HAVE_SYS_EVENT_H)
++__attribute__ ((visibility("default"))) int
++kqueue(void)
++{
++      wrapped_calls_kqueue++;
++
++      if (fall_back) {
++              wrapped_calls_kqueue++; /* kqueue() not wrapped */
++              errno = EINVAL;
++              return -1;
++      }
++
++      return real_kqueue();
++}
++#endif
+ 
+ static void
+ do_os_wrappers_socket_cloexec(int n)
+@@ -156,12 +194,14 @@ TEST(os_wrappers_socket_cloexec)
+       do_os_wrappers_socket_cloexec(0);
+ }
+ 
++#ifdef SOCK_CLOEXEC
+ TEST(os_wrappers_socket_cloexec_fallback)
+ {
+       /* forced fallback */
+       init_fallbacks(1);
+       do_os_wrappers_socket_cloexec(1);
+ }
++#endif
+ 
+ static void
+ do_os_wrappers_dupfd_cloexec(int n)
+@@ -195,11 +235,13 @@ TEST(os_wrappers_dupfd_cloexec)
+       do_os_wrappers_dupfd_cloexec(0);
+ }
+ 
++#ifdef F_DUPFD_CLOEXEC
+ TEST(os_wrappers_dupfd_cloexec_fallback)
+ {
+       init_fallbacks(1);
+       do_os_wrappers_dupfd_cloexec(3);
+ }
++#endif
+ 
+ struct marshal_data {
+       struct wl_connection *read_connection;
+@@ -218,8 +260,7 @@ struct marshal_data {
+ static void
+ setup_marshal_data(struct marshal_data *data)
+ {
+-      assert(socketpair(AF_UNIX,
+-                        SOCK_STREAM | SOCK_CLOEXEC, 0, data->s) == 0);
++      assert(wl_os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, data->s) == 0);
+ 
+       data->read_connection = wl_connection_create(data->s[0]);
+       assert(data->read_connection);
+@@ -328,21 +369,23 @@ TEST(os_wrappers_recvmsg_cloexec)
+       do_os_wrappers_recvmsg_cloexec(0);
+ }
+ 
++#ifdef MSG_CMSG_CLOEXEC
+ TEST(os_wrappers_recvmsg_cloexec_fallback)
+ {
+       init_fallbacks(1);
+       do_os_wrappers_recvmsg_cloexec(1);
+ }
++#endif
+ 
+ static void
+-do_os_wrappers_epoll_create_cloexec(int n)
++do_os_wrappers_queue_create_cloexec(int n)
+ {
+       int fd;
+       int nr_fds;
+ 
+       nr_fds = count_open_fds();
+ 
+-      fd = wl_os_epoll_create_cloexec();
++      fd = wl_os_queue_create_cloexec();
+       assert(fd >= 0);
+ 
+ #ifdef EPOLL_CLOEXEC
+@@ -357,13 +400,13 @@ do_os_wrappers_epoll_create_cloexec(int 
+ TEST(os_wrappers_epoll_create_cloexec)
+ {
+       init_fallbacks(0);
+-      do_os_wrappers_epoll_create_cloexec(1);
++      do_os_wrappers_queue_create_cloexec(1);
+ }
+ 
+ TEST(os_wrappers_epoll_create_cloexec_fallback)
+ {
+       init_fallbacks(1);
+-      do_os_wrappers_epoll_create_cloexec(2);
++      do_os_wrappers_queue_create_cloexec(2);
+ }
+ 
+ /* FIXME: add tests for wl_os_accept_cloexec() */
Index: pkgsrc/devel/wayland/patches/patch-tests_queue-test.c
diff -u /dev/null pkgsrc/devel/wayland/patches/patch-tests_queue-test.c:1.1
--- /dev/null   Sun Aug 18 16:05:12 2019
+++ pkgsrc/devel/wayland/patches/patch-tests_queue-test.c       Sun Aug 18 16:05:12 2019
@@ -0,0 +1,25 @@
+$NetBSD: patch-tests_queue-test.c,v 1.1 2019/08/18 16:05:12 nia Exp $
+
+BSD support from FreeBSD
+
+--- tests/queue-test.c.orig    2016-10-22 16:23:10 UTC
++++ tests/queue-test.c
+@@ -23,6 +23,8 @@
+  * SOFTWARE.
+  */
+ 
++#include "../config.h"
++
+ #include <stdlib.h>
+ #include <stdint.h>
+ #include <stdio.h>
+@@ -31,6 +33,9 @@
+ #include <sys/types.h>
+ #include <sys/wait.h>
+ #include <assert.h>
++#ifdef HAVE_SIGNAL_H
++#include <signal.h>
++#endif
+ 
+ #include "wayland-client.h"
+ #include "wayland-server.h"
Index: pkgsrc/devel/wayland/patches/patch-tests_sanity-test.c
diff -u /dev/null pkgsrc/devel/wayland/patches/patch-tests_sanity-test.c:1.1
--- /dev/null   Sun Aug 18 16:05:12 2019
+++ pkgsrc/devel/wayland/patches/patch-tests_sanity-test.c      Sun Aug 18 16:05:12 2019
@@ -0,0 +1,27 @@
+$NetBSD: patch-tests_sanity-test.c,v 1.1 2019/08/18 16:05:12 nia Exp $
+
+BSD support from FreeBSD
+
+--- tests/sanity-test.c.orig   2019-03-21 00:55:25.000000000 +0000
++++ tests/sanity-test.c
+@@ -87,7 +87,8 @@ FAIL_TEST(sanity_fd_leak)
+ {
+       int fd[2];
+ 
+-      assert(fd_leak_check_enabled);
++// XXX FreeBSD disables leak checks...
++//    assert(fd_leak_check_enabled);
+ 
+       /* leak 2 file descriptors */
+       if (pipe(fd) < 0)
+@@ -124,8 +125,8 @@ static void
+ sanity_fd_no_leak(void)
+ {
+       int fd[2];
+-
+-      assert(fd_leak_check_enabled);
++// XXX FreeBSD disables leak checks...
++//    assert(fd_leak_check_enabled);
+ 
+       /* leak 2 file descriptors */
+       if (pipe(fd) < 0)
Index: pkgsrc/devel/wayland/patches/patch-tests_test-helpers.c
diff -u /dev/null pkgsrc/devel/wayland/patches/patch-tests_test-helpers.c:1.1
--- /dev/null   Sun Aug 18 16:05:12 2019
+++ pkgsrc/devel/wayland/patches/patch-tests_test-helpers.c     Sun Aug 18 16:05:12 2019
@@ -0,0 +1,56 @@
+$NetBSD: patch-tests_test-helpers.c,v 1.1 2019/08/18 16:05:12 nia Exp $
+
+BSD support from FreeBSD
+
+--- tests/test-helpers.c.orig  2019-03-21 00:55:25.000000000 +0000
++++ tests/test-helpers.c
+@@ -25,6 +25,12 @@
+ 
+ #include "config.h"
+ 
++#include "../config.h"
++
++#ifdef HAVE_SYS_PARAM_H
++#include <sys/param.h>
++#endif
++
+ #include <assert.h>
+ #include <errno.h>
+ #include <dirent.h>
+@@ -40,6 +46,16 @@
+ 
+ #include "test-runner.h"
+ 
++#ifdef __FreeBSD__
++/* FreeBSD uses fdescfs (which must be mounted using:
++ *    mount -t fdescfs fdescfs /dev/fd
++ * before the test suite can be run). */
++#define OPEN_FDS_DIR "/dev/fd"
++#else
++/* Linux. */
++#define OPEN_FDS_DIR "/proc/self/fd"
++#endif
++
+ int
+ count_open_fds(void)
+ {
+@@ -47,8 +63,8 @@ count_open_fds(void)
+       struct dirent *ent;
+       int count = 0;
+ 
+-      dir = opendir("/proc/self/fd");
+-      assert(dir && "opening /proc/self/fd failed.");
++      dir = opendir(OPEN_FDS_DIR);
++      assert(dir && "opening " OPEN_FDS_DIR " failed.");
+ 
+       errno = 0;
+       while ((ent = readdir(dir))) {
+@@ -57,7 +73,7 @@ count_open_fds(void)
+                       continue;
+               count++;
+       }
+-      assert(errno == 0 && "reading /proc/self/fd failed.");
++      assert(errno == 0 && "reading " OPEN_FDS_DIR " failed.");
+ 
+       closedir(dir);
+ 
Index: pkgsrc/devel/wayland/patches/patch-tests_test-runner.c
diff -u /dev/null pkgsrc/devel/wayland/patches/patch-tests_test-runner.c:1.1
--- /dev/null   Sun Aug 18 16:05:12 2019
+++ pkgsrc/devel/wayland/patches/patch-tests_test-runner.c      Sun Aug 18 16:05:12 2019
@@ -0,0 +1,139 @@
+$NetBSD: patch-tests_test-runner.c,v 1.1 2019/08/18 16:05:12 nia Exp $
+
+BSD support from FreeBSD
+
+--- tests/test-runner.c.orig   2019-03-21 00:55:25.000000000 +0000
++++ tests/test-runner.c
+@@ -25,6 +25,12 @@
+ 
+ #define _GNU_SOURCE
+ 
++#include "../config.h"
++
++#ifdef HAVE_SYS_PARAM_H
++#include <sys/param.h>
++#endif
++
+ #include <unistd.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+@@ -37,13 +43,28 @@
+ #include <errno.h>
+ #include <limits.h>
+ #include <sys/ptrace.h>
++#ifdef HAVE_SYS_PRCTL_H
+ #include <sys/prctl.h>
++#endif
++#include <signal.h>
+ #ifndef PR_SET_PTRACER
+ # define PR_SET_PTRACER 0x59616d61
+ #endif
+ 
+ #include "test-runner.h"
+ 
++#ifndef PTRACE_ATTACH
++#define PTRACE_ATTACH PT_ATTACH
++#endif
++
++#ifndef PTRACE_CONT
++#define PTRACE_CONT PT_CONTINUE
++#endif
++
++#ifndef PTRACE_DETACH
++#define PTRACE_DETACH PT_DETACH
++#endif
++
+ /* when set to 1, check if tests are not leaking opened files.
+  * It is turned on by default. It can be turned off by
+  * WAYLAND_TEST_NO_LEAK_CHECK environment variable. */
+@@ -51,7 +72,7 @@ int fd_leak_check_enabled;
+ 
+ /* when this var is set to 0, every call to test_set_timeout() is
+  * suppressed - handy when debugging the test. Can be set by
+- * WAYLAND_TEST_NO_TIMEOUTS environment variable. */
++ * WAYLAND_TESTS_NO_TIMEOUTS evnironment var */
+ static int timeouts_enabled = 1;
+ 
+ /* set to one if the output goes to the terminal */
+@@ -239,6 +260,8 @@ is_debugger_attached(void)
+               return 0;
+       }
+ 
++
++// xxx start here
+       pid = fork();
+       if (pid == -1) {
+               perror("fork");
+@@ -259,13 +282,14 @@ is_debugger_attached(void)
+                       _exit(1);
+               if (!waitpid(-1, NULL, 0))
+                       _exit(1);
+-              ptrace(PTRACE_CONT, NULL, NULL);
++              ptrace(PTRACE_CONT, ppid, NULL, NULL);
+               ptrace(PTRACE_DETACH, ppid, NULL, NULL);
+               _exit(0);
+       } else {
+               close(pipefd[0]);
+ 
+               /* Enable child to ptrace the parent process */
++#if defined(HAVE_PRCTL)
+               rc = prctl(PR_SET_PTRACER, pid);
+               if (rc != 0 && errno != EINVAL) {
+                       /* An error prevents us from telling if a debugger is attached.
+@@ -275,7 +299,9 @@ is_debugger_attached(void)
+                        */
+                       perror("prctl");
+                       write(pipefd[1], "-", 1);
+-              } else {
++              } else
++#endif
++              {
+                       /* Signal to client that parent is ready by passing '+' */
+                       write(pipefd[1], "+", 1);
+               }
+@@ -295,9 +321,6 @@ int main(int argc, char *argv[])
+       int total, pass;
+       siginfo_t info;
+ 
+-      if (isatty(fileno(stderr)))
+-              is_atty = 1;
+-
+       if (is_debugger_attached()) {
+               fd_leak_check_enabled = 0;
+               timeouts_enabled = 0;
+@@ -336,7 +359,8 @@ int main(int argc, char *argv[])
+               if (pid == 0)
+                       run_test(t); /* never returns */
+ 
+-              if (waitid(P_PID, pid, &info, WEXITED)) {
++#ifdef HAVE_WAITID
++              if (waitid(P_PID, 0, &info, WEXITED)) {
+                       stderr_set_color(RED);
+                       fprintf(stderr, "waitid failed: %m\n");
+                       stderr_reset_color();
+@@ -367,6 +391,25 @@ int main(int argc, char *argv[])
+ 
+                       break;
+               }
++#else
++               if (waitpid(-1, &status, 0) == -1) {
++                       fprintf(stderr, "waitpid failed: %s\n",
++                               strerror(errno));
++                       abort();
++               }
++
++               fprintf(stderr, "test \"%s\":\t", t->name);
++               if (WIFEXITED(status)) {
++                       fprintf(stderr, "exit status %d", WEXITSTATUS(status));
++                       if (WEXITSTATUS(status) == EXIT_SUCCESS)
++                               success = 1;
++               } else if (WIFSIGNALED(status)) {
++                       fprintf(stderr, "signal %d", WTERMSIG(status));
++               }
++#endif
++
++              if (t->must_fail)
++                      success = !success;
+ 
+               if (success) {
+                       pass++;



Home | Main Index | Thread Index | Old Index