[PATCH v3 03/10] client: define EPROTO if it's not defined

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 src/wayland-client.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/src/wayland-client.h b/src/wayland-client.h
index 9f70fa3..690c446 100644
--- a/src/wayland-client.h
+++ b/src/wayland-client.h
@@ -39,4 +39,8 @@
 #include "wayland-client-core.h"
 #include "wayland-client-protocol.h"
 
+#ifndef EPROTO
+#define EPROTO ENOPROTOOPT
+#endif
+
 #endif
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH v3 10/10] shm: use workaround if mremap() is not available

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 configure.ac  |  4 
 src/wayland-shm.c | 30 ++
 2 files changed, 34 insertions(+)

diff --git a/configure.ac b/configure.ac
index 40cbd08..f49ca24 100644
--- a/configure.ac
+++ b/configure.ac
@@ -104,6 +104,10 @@ AC_SUBST(RT_LIBS)
 # Defines __FreeBSD__ if we're on FreeBSD, same for other *BSD
 AC_CHECK_HEADERS([sys/param.h])
 
+# mremap() and sys/mman.h are needed for the shm
+AC_CHECK_FUNCS([mremap])
+AC_CHECK_HEADERS([sys/mman.h])
+
 # waitid() and signal.h are needed for the test suite.
 AC_CHECK_FUNCS([waitid])
 AC_CHECK_HEADERS([signal.h])
diff --git a/src/wayland-shm.c b/src/wayland-shm.c
index 6f2b1d8..567dedf 100644
--- a/src/wayland-shm.c
+++ b/src/wayland-shm.c
@@ -42,6 +42,9 @@
 #include 
 #include 
 #include 
+#ifdef HAVE_SYS_PARAM_H
+#include 
+#endif
 
 #include "wayland-util.h"
 #include "wayland-private.h"
@@ -87,7 +90,24 @@ shm_pool_finish_resize(struct wl_shm_pool *pool)
if (pool->size == pool->new_size)
return;
 
+#ifdef HAVE_MREMAP
data = mremap(pool->data, pool->size, pool->new_size, MREMAP_MAYMOVE);
+#else
+   int32_t osize = (pool->size + PAGE_SIZE - 1) & ~PAGE_MASK;
+   if (pool->new_size <= osize) {
+   pool->size = pool->new_size;
+   return;
+   }
+   data = mmap(pool->data + osize, pool->new_size - osize, PROT_READ,
+   MAP_SHARED | MAP_TRYFIXED, pool->fd, osize);
+   if (data == MAP_FAILED) {
+   munmap(pool->data, pool->size);
+   data = mmap(NULL, pool->new_size, PROT_READ, MAP_SHARED, 
pool->fd, 0);
+   } else {
+   pool->size = pool->new_size;
+   return;
+   }
+#endif
if (data == MAP_FAILED) {
wl_resource_post_error(pool->resource,
   WL_SHM_ERROR_INVALID_FD,
@@ -505,6 +525,7 @@ sigbus_handler(int signum, siginfo_t *info, void *context)
sigbus_data->fallback_mapping_used = 1;
 
/* This should replace the previous mapping */
+#ifdef HAVE_MREMAP
if (mmap(pool->data, pool->size,
 PROT_READ | PROT_WRITE,
 MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS,
@@ -512,6 +533,15 @@ sigbus_handler(int signum, siginfo_t *info, void *context)
reraise_sigbus();
return;
}
+#else
+   if (mmap(pool->data, pool->size,
+PROT_READ,
+MAP_PRIVATE | MAP_FIXED | MAP_ANON,
+0, 0) == MAP_FAILED) {
+   reraise_sigbus();
+   return;
+   }
+#endif
 }
 
 static void
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH v3 05/10] core: support kqueue

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 Makefile.am  |   3 +-
 configure.ac |  19 +-
 doc/doxygen/Makefile.am  |   3 +-
 src/{event-loop.c => event-loop-epoll.c} |   4 +
 src/event-loop-kqueue.c  | 800 +++
 src/wayland-os.c |  47 +-
 src/wayland-os.h |   2 +-
 tests/os-wrappers-test.c |  55 +-
 8 files changed, 915 insertions(+), 18 deletions(-)
 rename src/{event-loop.c => event-loop-epoll.c} (99%)
 create mode 100644 src/event-loop-kqueue.c

diff --git a/Makefile.am b/Makefile.am
index 435957f..44b58c4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -76,7 +76,8 @@ libwayland_server_la_LDFLAGS = -version-info 1:0:1
 libwayland_server_la_SOURCES = \
src/wayland-server.c\
src/wayland-shm.c   \
-   src/event-loop.c
+   src/event-loop-epoll.c  \
+   src/event-loop-kqueue.c
 
 nodist_libwayland_server_la_SOURCES =  \
protocol/wayland-server-protocol.h  \
diff --git a/configure.ac b/configure.ac
index 9ca2331..8563968 100644
--- a/configure.ac
+++ b/configure.ac
@@ -65,6 +65,11 @@ 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
+
 # Replacement for /proc on BSD
 AC_CHECK_HEADERS([kvm.h])
 SAVE_LIBS="$LIBS"
@@ -128,12 +133,14 @@ 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 ]])
-   AC_CHECK_DECL(TFD_CLOEXEC,[],
- [AC_MSG_ERROR("TFD_CLOEXEC is needed to compile wayland 
libraries")],
- [[#include ]])
+   if test "x$ac_cv_header_sys_epoll_h" == "xyes"; then
+   AC_CHECK_DECL(SFD_CLOEXEC,[],
+ [AC_MSG_ERROR("SFD_CLOEXEC is needed to compile 
wayland libraries")],
+ [[#include ]])
+   AC_CHECK_DECL(TFD_CLOEXEC,[],
+ [AC_MSG_ERROR("TFD_CLOEXEC is needed to compile 
wayland libraries")],
+ [[#include ]])
+   fi
AC_CHECK_DECL(CLOCK_MONOTONIC,[],
  [AC_MSG_ERROR("CLOCK_MONOTONIC is needed to compile 
wayland libraries")],
  [[#include ]])
diff --git a/doc/doxygen/Makefile.am b/doc/doxygen/Makefile.am
index f8b0b3a..60bed53 100644
--- a/doc/doxygen/Makefile.am
+++ b/doc/doxygen/Makefile.am
@@ -19,7 +19,8 @@ scanned_src_files_Client =\
 
 scanned_src_files_Server = \
$(scanned_src_files_shared) \
-   $(top_srcdir)/src/event-loop.c  \
+   $(top_srcdir)/src/event-loop-epoll.c\
+   $(top_srcdir)/src/event-loop-kqueue.c   \
$(top_srcdir)/src/wayland-server.c  \
$(top_srcdir)/src/wayland-server.h  \
$(top_srcdir)/src/wayland-server-core.h \
diff --git a/src/event-loop.c b/src/event-loop-epoll.c
similarity index 99%
rename from src/event-loop.c
rename to src/event-loop-epoll.c
index eb2dce6..0242b86 100644
--- a/src/event-loop.c
+++ b/src/event-loop-epoll.c
@@ -23,6 +23,9 @@
  * SOFTWARE.
  */
 
+#include "config.h"
+
+#ifdef HAVE_SYS_EPOLL_H
 #include 
 #include 
 #include 
@@ -702,3 +705,4 @@ wl_event_loop_get_destroy_listener(struct wl_event_loop 
*loop,
 {
return wl_signal_get(&loop->destroy_signal, notify);
 }
+#endif
diff --git a/src/event-loop-kqueue.c b/src/event-loop-kqueue.c
new file mode 100644
index 000..c8a1047
--- /dev/null
+++ b/src/event-loop-kqueue.c
@@ -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, FITNES

[PATCH v3 09/10] tests: add OS-specific tracing to runner

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 configure.ac|  3 +++
 tests/test-runner.c | 22 +-
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 15535ff..40cbd08 100644
--- a/configure.ac
+++ b/configure.ac
@@ -101,6 +101,9 @@ RT_LIBS="$LIBS"
 LIBS="$SAVE_LIBS"
 AC_SUBST(RT_LIBS)
 
+# Defines __FreeBSD__ if we're on FreeBSD, same for other *BSD
+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])
diff --git a/tests/test-runner.c b/tests/test-runner.c
index 7fa72eb..4791092 100644
--- a/tests/test-runner.c
+++ b/tests/test-runner.c
@@ -40,13 +40,26 @@
 #include 
 #include 
 #include 
+#ifdef HAVE_SYS_PRCTL_H
 #include 
+#endif
+#ifdef HAVE_SYS_PARAM_H
+#include 
+#endif
 #ifndef PR_SET_PTRACER
 # define PR_SET_PTRACER 0x59616d61
 #endif
 
 #include "test-runner.h"
 
+extern const struct test __start_test_section, __stop_test_section;
+
+#ifndef __linux__
+#define PTRACE_ATTACH PT_ATTACH
+#define PTRACE_CONT PT_CONTINUE
+#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. */
@@ -232,6 +245,10 @@ stderr_reset_color(void)
 static int
 is_debugger_attached(void)
 {
+#ifdef __OpenBSD__
+   /* OpenBSD doesn't allow to trace parent process */
+   return 0;
+#else
int status;
int rc;
pid_t pid;
@@ -262,13 +279,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 */
+#ifdef HAVE_SYS_PRCTL_H
rc = prctl(PR_SET_PTRACER, pid);
if (rc != 0 && errno != EINVAL) {
/* An error prevents us from telling if a debugger is 
attached.
@@ -282,6 +300,7 @@ is_debugger_attached(void)
/* Signal to client that parent is ready by passing '+' 
*/
write(pipefd[1], "+", 1);
}
+#endif
close(pipefd[1]);
 
waitpid(pid, &status, 0);
@@ -289,6 +308,7 @@ is_debugger_attached(void)
}
 
return rc;
+#endif
 }
 
 int main(int argc, char *argv[])
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH v3 08/10] server: add *BSD credentials support

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 configure.ac |  3 +++
 src/wayland-server.c | 35 +++
 src/wayland-shm.c| 10 ++
 3 files changed, 48 insertions(+)

diff --git a/configure.ac b/configure.ac
index 3c227a2..15535ff 100644
--- a/configure.ac
+++ b/configure.ac
@@ -70,6 +70,9 @@ if test "x$ac_cv_header_sys_epoll_h" != "xyes" && test 
"x$ac_cv_header_sys_event
AC_MSG_ERROR([Can't find sys/epoll.h or sys/event.h. Please ensure 
either epoll or kqueue is available.])
 fi
 
+# Credential support on BSD
+AC_CHECK_HEADERS([sys/ucred.h])
+
 # Replacement for /proc on BSD
 AC_CHECK_HEADERS([kvm.h])
 SAVE_LIBS="$LIBS"
diff --git a/src/wayland-server.c b/src/wayland-server.c
index 19f6a76..64d021f 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -23,8 +23,15 @@
  * SOFTWARE.
  */
 
+#include "config.h"
+
 #define _GNU_SOURCE
 
+#ifdef HAVE_SYS_UCRED_H
+#include 
+#include 
+#endif
+
 #include 
 #include 
 #include 
@@ -77,7 +84,11 @@ struct wl_client {
struct wl_list link;
struct wl_map objects;
struct wl_priv_signal destroy_signal;
+#ifdef HAVE_SYS_UCRED_H
+   struct xucred xucred;
+#else
struct ucred ucred;
+#endif
int error;
struct wl_priv_signal resource_created_signal;
 };
@@ -312,7 +323,11 @@ wl_resource_post_error(struct wl_resource *resource,
 static void
 destroy_client_with_error(struct wl_client *client, const char *reason)
 {
+#ifdef HAVE_SYS_UCRED_H
+   wl_log("%s (uid %u)\n", reason, client->xucred.cr_uid);
+#else
wl_log("%s (pid %u)\n", reason, client->ucred.pid);
+#endif
wl_client_destroy(client);
 }
 
@@ -526,10 +541,22 @@ wl_client_create(struct wl_display *display, int fd)
if (!client->source)
goto err_client;
 
+#ifdef HAVE_SYS_UCRED_H
+   len = sizeof client->xucred;
+   if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED,
+  &client->xucred, &len) < 0
+# ifdef XUCRED_VERSION
+  /* FreeBSD */
+  || client->xucred.cr_version != XUCRED_VERSION
+# endif
+ )
+   goto err_source;
+#else
len = sizeof client->ucred;
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED,
   &client->ucred, &len) < 0)
goto err_source;
+#endif
 
client->connection = wl_connection_create(fd);
if (client->connection == NULL)
@@ -583,12 +610,20 @@ 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
+   *pid = 0; /* FIXME: pid is not defined on BSD */
+   if (uid)
+   *uid = client->xucred.cr_uid;
+   if (gid)
+   *gid = client->xucred.cr_gid;
+#else
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
diff --git a/src/wayland-shm.c b/src/wayland-shm.c
index 4191231..6f2b1d8 100644
--- a/src/wayland-shm.c
+++ b/src/wayland-shm.c
@@ -28,6 +28,8 @@
  *
  */
 
+#include "config.h"
+
 #define _GNU_SOURCE
 
 #include 
@@ -59,6 +61,7 @@ struct wl_shm_pool {
char *data;
int32_t size;
int32_t new_size;
+   int fd;
 };
 
 struct wl_shm_buffer {
@@ -110,6 +113,9 @@ shm_pool_unref(struct wl_shm_pool *pool, bool external)
if (pool->internal_refcount + pool->external_refcount)
return;
 
+#ifdef HAVE_SYS_UCRED_H
+   close(pool->fd);
+#endif
munmap(pool->data, pool->size);
free(pool);
 }
@@ -284,7 +290,11 @@ shm_create_pool(struct wl_client *client, struct 
wl_resource *resource,
   "failed mmap fd %d: %m", fd);
goto err_free;
}
+#ifdef HAVE_SYS_UCRED_H
+   pool->fd = fd;
+#else
close(fd);
+#endif
 
pool->resource =
wl_resource_create(client, &wl_shm_pool_interface, 1, id);
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH v3 04/10] tests: use *BSD replacement for /proc

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 Makefile.am  |  1 +
 configure.ac | 12 
 tests/test-helpers.c | 31 ++-
 3 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/Makefile.am b/Makefile.am
index 489f581..435957f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -215,6 +215,7 @@ noinst_LTLIBRARIES +=   \
libtest-helpers.la
 
 libtest_helpers_la_SOURCES = tests/test-helpers.c
+libtest_helpers_la_LIBADD = $(KVM_LIBS)
 
 libtest_runner_la_SOURCES =\
tests/test-runner.c \
diff --git a/configure.ac b/configure.ac
index f53408a..9ca2331 100644
--- a/configure.ac
+++ b/configure.ac
@@ -65,6 +65,18 @@ AC_SUBST(GCC_CFLAGS)
 AC_CHECK_HEADERS([sys/prctl.h])
 AC_CHECK_FUNCS([accept4 mkostemp posix_fallocate prctl])
 
+# Replacement for /proc on BSD
+AC_CHECK_HEADERS([kvm.h])
+SAVE_LIBS="$LIBS"
+LIBS=
+AC_CHECK_LIB([kvm], [kvm_getfiles])
+KVM_LIBS="$LIBS"
+LIBS="$SAVE_LIBS"
+AC_SUBST(KVM_LIBS)
+if test "x$ac_cv_header_kvm_h" != "x" && test "x$ac_cv_lib_kvm_kvm_getfiles" 
!= "x"; then
+   AC_DEFINE(USE_LIBKVM, 1, [use libkvm on BSD])
+fi
+
 # *BSD don't have libdl, but they have its functions
 SAVE_LIBS="$LIBS"
 LIBS=
diff --git a/tests/test-helpers.c b/tests/test-helpers.c
index b2189d8..4b90a10 100644
--- a/tests/test-helpers.c
+++ b/tests/test-helpers.c
@@ -25,9 +25,18 @@
 
 #include "config.h"
 
-#include 
+#ifdef USE_LIBKVM
+#include 
+#include 
+#include 
+#include 
+#include 
+#else
 #include 
 #include 
+#endif
+
+#include 
 #include 
 #include 
 #include 
@@ -43,6 +52,25 @@
 int
 count_open_fds(void)
 {
+#ifdef USE_LIBKVM
+   /* Use BSD-specific kernel memory interface */
+
+   struct kinfo_file *kif;
+   kvm_t *kd;
+   int count;
+   char errstr[_POSIX2_LINE_MAX];
+
+   kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY|KVM_NO_FILES, errstr);
+   assert(kd != NULL);
+   kif = kvm_getfiles(kd, KERN_FILE_BYPID, getpid(), sizeof(struct 
kinfo_file), &count);
+   assert(kif != NULL);
+
+   /* KVM library frees memory on itself */
+   kvm_close(kd);
+   return count;
+#else
+   /* Use /proc filesystem. */
+
DIR *dir;
struct dirent *ent;
int count = 0;
@@ -62,6 +90,7 @@ count_open_fds(void)
closedir(dir);
 
return count;
+#endif
 }
 
 void
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH v3 01/10] tests: fix main symbol duplication

2019-02-08 Thread Leonid Bobrov
So far I got these errors before patching:

libtool: link: cc -o .libs/headers-test -pthread -Wall -Wextra 
-Wno-unused-parameter -g -Wstrict-prototypes -Wmissing-prototypes 
-fvisibility=hidden -O2 -pipe tests/headers-test.o 
tests/headers-protocol-test.o tests/headers-protocol-core-test.o 
/tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a -L.libs 
-lwayland-client -lffi -lm -lwayland-server -lkvm -Wl,-rpath-link,/usr/local/lib
ld: error: duplicate symbol: main
>>> defined at headers-test.c:53 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/headers-test.c:53)
>>>tests/headers-test.o:(main)
>>> defined at test-runner.c:377 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/test-runner.c:377)
>>>test-runner.o:(.text+0x250) in archive 
>>> /tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a

libtool: link: cc -o .libs/exec-fd-leak-checker -pthread -Wall -Wextra 
-Wno-unused-parameter -g -Wstrict-prototypes -Wmissing-prototypes 
-fvisibility=hidden -O2 -pipe tests/exec-fd-leak-checker.o 
/tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a -L.libs 
-lwayland-client -lffi -lm -lwayland-server -lkvm -Wl,-rpath-link,/usr/local/lib
ld: error: duplicate symbol: main
>>> defined at exec-fd-leak-checker.c:57 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/exec-fd-leak-checker.c:57)
>>>tests/exec-fd-leak-checker.o:(main)
>>> defined at test-runner.c:377 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/test-runner.c:377)
>>>test-runner.o:(.text+0x250) in archive 
>>> /tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a

Makefile.am: error: object 'tests/test-helpers.$(OBJEXT)' created both with 
libtool and without

libtool: link: cc -o .libs/fixed-benchmark -pthread -Wall -Wextra 
-Wno-unused-parameter -g -Wstrict-prototypes -Wmissing-prototypes 
-fvisibility=hidden -O2 -pipe tests/fixed-benchmark.o 
/tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a -L.libs 
-lwayland-client -lffi -lm -lwayland-server -lkvm -Wl,-rpath-link,/usr/local/lib
ld: error: duplicate symbol: main
>>> defined at fixed-benchmark.c:100 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/fixed-benchmark.c:100)
>>>tests/fixed-benchmark.o:(main)
>>> defined at test-runner.c:377 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/test-runner.c:377)
>>>test-runner.o:(.text+0x250) in archive 
>>> /tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a

This commit fixes all of that.

Signed-off-by: Leonid Bobrov 
---
 Makefile.am | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 697c517..f47d055 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -210,12 +210,15 @@ noinst_PROGRAMS = \
exec-fd-leak-checker\
fixed-benchmark
 
-noinst_LTLIBRARIES += libtest-runner.la
+noinst_LTLIBRARIES +=  \
+   libtest-runner.la   \
+   libtest-helpers.la
+
+libtest_helpers_la_SOURCES = tests/test-helpers.c
 
 libtest_runner_la_SOURCES =\
tests/test-runner.c \
tests/test-runner.h \
-   tests/test-helpers.c\
tests/test-compositor.h \
tests/test-compositor.c
 libtest_runner_la_LIBADD = \
@@ -223,9 +226,9 @@ libtest_runner_la_LIBADD =  \
libwayland-util.la  \
libwayland-client.la\
libwayland-server.la\
+   libtest-helpers.la  \
-lrt -ldl $(FFI_LIBS)
 
-
 array_test_SOURCES = tests/array-test.c
 array_test_LDADD = libtest-runner.la
 client_test_SOURCES = tests/client-test.c
@@ -270,7 +273,6 @@ protocol_logger_test_LDADD = libtest-runner.la
 headers_test_SOURCES = tests/headers-test.c \
   tests/headers-protocol-test.c \
   tests/headers-protocol-core-test.c
-headers_test_LDADD = libtest-runner.la
 nodist_headers_test_SOURCES =  \
protocol/wayland-server-protocol-core.h \
protocol/wayland-client-protocol-core.h
@@ -280,13 +282,12 @@ cpp_compile_test_SOURCES = tests/cpp-compile-test.cpp
 endif
 
 fixed_benchmark_SOURCES = tests/fixed-benchmark.c
-fixed_benchmark_LDADD = libtest-runner.la
 
 os_wrappers_test_SOURCES = tests/os-wrappers-test.c
 os_wrappers_test_LDADD = libtest-runner.la
 
 exec_fd_leak_checker_SOURCES = tests/exec-fd-leak-checker.c
-exec_fd_leak_checker_LDADD = libtest-runner.la
+exec_fd_leak_checker_LDADD = libtest-helpers.la
 
 EXTRA_DIST += tests/scanner-test.sh\
protocol/tests.xml  \
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH v3 02/10] configure: detect libdl and librt

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 Makefile.am  |  6 +++---
 configure.ac | 16 
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index f47d055..489f581 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -71,7 +71,7 @@ nodist_include_HEADERS =  \
protocol/wayland-client-protocol.h
 
 libwayland_server_la_CFLAGS = $(FFI_CFLAGS) $(AM_CFLAGS) -pthread
-libwayland_server_la_LIBADD = $(FFI_LIBS) libwayland-private.la 
libwayland-util.la -lrt -lm
+libwayland_server_la_LIBADD = $(FFI_LIBS) libwayland-private.la 
libwayland-util.la $(RT_LIBS) -lm
 libwayland_server_la_LDFLAGS = -version-info 1:0:1
 libwayland_server_la_SOURCES = \
src/wayland-server.c\
@@ -83,7 +83,7 @@ nodist_libwayland_server_la_SOURCES = \
protocol/wayland-protocol.c
 
 libwayland_client_la_CFLAGS = $(FFI_CFLAGS) $(AM_CFLAGS) -pthread
-libwayland_client_la_LIBADD = $(FFI_LIBS) libwayland-private.la 
libwayland-util.la -lrt -lm
+libwayland_client_la_LIBADD = $(FFI_LIBS) libwayland-private.la 
libwayland-util.la $(RT_LIBS) -lm
 libwayland_client_la_LDFLAGS = -version-info 3:0:3
 libwayland_client_la_SOURCES = \
src/wayland-client.c
@@ -227,7 +227,7 @@ libtest_runner_la_LIBADD =  \
libwayland-client.la\
libwayland-server.la\
libtest-helpers.la  \
-   -lrt -ldl $(FFI_LIBS)
+   $(RT_LIBS) $(DL_LIBS) $(FFI_LIBS)
 
 array_test_SOURCES = tests/array-test.c
 array_test_LDADD = libtest-runner.la
diff --git a/configure.ac b/configure.ac
index 18fb649..f53408a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -65,6 +65,22 @@ AC_SUBST(GCC_CFLAGS)
 AC_CHECK_HEADERS([sys/prctl.h])
 AC_CHECK_FUNCS([accept4 mkostemp posix_fallocate prctl])
 
+# *BSD don't have libdl, but they have its functions
+SAVE_LIBS="$LIBS"
+LIBS=
+AC_CHECK_LIB([dl], [dlsym])
+DL_LIBS="$LIBS"
+LIBS="$SAVE_LIBS"
+AC_SUBST(DL_LIBS)
+
+# *BSD don't have librt, but they have its functions
+SAVE_LIBS="$LIBS"
+LIBS=
+AC_CHECK_LIB([rt], [clock_gettime])
+RT_LIBS="$LIBS"
+LIBS="$SAVE_LIBS"
+AC_SUBST(RT_LIBS)
+
 AC_ARG_ENABLE([libraries],
  [AC_HELP_STRING([--disable-libraries],
  [Disable compilation of wayland libraries])],
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH v3 07/10] tests: support waitpid()

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 configure.ac|  4 
 tests/test-compositor.c | 25 +++--
 tests/test-runner.c | 29 -
 3 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/configure.ac b/configure.ac
index 8563968..3c227a2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -98,6 +98,10 @@ RT_LIBS="$LIBS"
 LIBS="$SAVE_LIBS"
 AC_SUBST(RT_LIBS)
 
+# 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])],
diff --git a/tests/test-compositor.c b/tests/test-compositor.c
index 72f6351..6e12630 100644
--- a/tests/test-compositor.c
+++ b/tests/test-compositor.c
@@ -23,6 +23,8 @@
  * SOFTWARE.
  */
 
+#include "config.h"
+
 #include 
 #include 
 #include 
@@ -86,8 +88,8 @@ get_socket_name(void)
static char retval[64];
 
gettimeofday(&tv, NULL);
-   snprintf(retval, sizeof retval, "wayland-test-%d-%ld%ld",
-getpid(), tv.tv_sec, tv.tv_usec);
+   snprintf(retval, sizeof retval, "wayland-test-%d-%lld%lld",
+getpid(), (long long)tv.tv_sec, (long long)tv.tv_usec);
 
return retval;
 }
@@ -97,10 +99,15 @@ handle_client_destroy(void *data)
 {
struct client_info *ci = data;
struct display *d;
+#ifdef HAVE_WAITID
siginfo_t status;
+#else
+   int istatus;
+#endif
 
d = ci->display;
 
+#ifdef HAVE_WAITID
assert(waitid(P_PID, ci->pid, &status, WEXITED) != -1);
 
switch (status.si_code) {
@@ -118,6 +125,20 @@ handle_client_destroy(void *data)
ci->exit_code = status.si_status;
break;
}
+#else
+   assert(waitpid(ci->pid, &istatus, WNOHANG) != -1);
+
+   if (WIFSIGNALED(istatus)) {
+   fprintf(stderr, "Client '%s' was killed by signal %d\n",
+   ci->name, WTERMSIG(istatus));
+   ci->exit_code = WEXITSTATUS(istatus);
+   } else if (WIFEXITED(istatus)) {
+   if (WEXITSTATUS(istatus) != EXIT_SUCCESS)
+   fprintf(stderr, "Client '%s' exited with code %d\n",
+   ci->name, WEXITSTATUS(istatus));
+   ci->exit_code = WEXITSTATUS(istatus);
+   }
+#endif
 
++d->clients_terminated_no;
if (d->clients_no == d->clients_terminated_no) {
diff --git a/tests/test-runner.c b/tests/test-runner.c
index 1487dc4..7fa72eb 100644
--- a/tests/test-runner.c
+++ b/tests/test-runner.c
@@ -23,6 +23,8 @@
  * SOFTWARE.
  */
 
+#include "config.h"
+
 #define _GNU_SOURCE
 
 #include 
@@ -32,6 +34,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -293,7 +296,11 @@ int main(int argc, char *argv[])
const struct test *t;
pid_t pid;
int total, pass;
+#ifdef HAVE_WAITID
siginfo_t info;
+#else
+   int status;
+#endif
 
if (isatty(fileno(stderr)))
is_atty = 1;
@@ -336,7 +343,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 +375,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++;
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH v3 06/10] core: define SO_PEERCRED if it's not defined

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 src/wayland-os.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/wayland-os.h b/src/wayland-os.h
index 321e34d..28e3350 100644
--- a/src/wayland-os.h
+++ b/src/wayland-os.h
@@ -41,6 +41,9 @@ wl_os_queue_create_cloexec(void);
 int
 wl_os_accept_cloexec(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
 
+#ifndef SO_PEERCRED
+#define SO_PEERCRED LOCAL_PEERCRED
+#endif
 
 /*
  * The following are for wayland-os.c and the unit tests.
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH v2 7/9] tests: support waitpid()

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 configure.ac|  4 
 tests/test-compositor.c | 25 +++--
 tests/test-runner.c | 29 -
 3 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/configure.ac b/configure.ac
index 8563968..3c227a2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -98,6 +98,10 @@ RT_LIBS="$LIBS"
 LIBS="$SAVE_LIBS"
 AC_SUBST(RT_LIBS)
 
+# 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])],
diff --git a/tests/test-compositor.c b/tests/test-compositor.c
index 72f6351..6e12630 100644
--- a/tests/test-compositor.c
+++ b/tests/test-compositor.c
@@ -23,6 +23,8 @@
  * SOFTWARE.
  */
 
+#include "config.h"
+
 #include 
 #include 
 #include 
@@ -86,8 +88,8 @@ get_socket_name(void)
static char retval[64];
 
gettimeofday(&tv, NULL);
-   snprintf(retval, sizeof retval, "wayland-test-%d-%ld%ld",
-getpid(), tv.tv_sec, tv.tv_usec);
+   snprintf(retval, sizeof retval, "wayland-test-%d-%lld%lld",
+getpid(), (long long)tv.tv_sec, (long long)tv.tv_usec);
 
return retval;
 }
@@ -97,10 +99,15 @@ handle_client_destroy(void *data)
 {
struct client_info *ci = data;
struct display *d;
+#ifdef HAVE_WAITID
siginfo_t status;
+#else
+   int istatus;
+#endif
 
d = ci->display;
 
+#ifdef HAVE_WAITID
assert(waitid(P_PID, ci->pid, &status, WEXITED) != -1);
 
switch (status.si_code) {
@@ -118,6 +125,20 @@ handle_client_destroy(void *data)
ci->exit_code = status.si_status;
break;
}
+#else
+   assert(waitpid(ci->pid, &istatus, WNOHANG) != -1);
+
+   if (WIFSIGNALED(istatus)) {
+   fprintf(stderr, "Client '%s' was killed by signal %d\n",
+   ci->name, WTERMSIG(istatus));
+   ci->exit_code = WEXITSTATUS(istatus);
+   } else if (WIFEXITED(istatus)) {
+   if (WEXITSTATUS(istatus) != EXIT_SUCCESS)
+   fprintf(stderr, "Client '%s' exited with code %d\n",
+   ci->name, WEXITSTATUS(istatus));
+   ci->exit_code = WEXITSTATUS(istatus);
+   }
+#endif
 
++d->clients_terminated_no;
if (d->clients_no == d->clients_terminated_no) {
diff --git a/tests/test-runner.c b/tests/test-runner.c
index 1487dc4..7fa72eb 100644
--- a/tests/test-runner.c
+++ b/tests/test-runner.c
@@ -23,6 +23,8 @@
  * SOFTWARE.
  */
 
+#include "config.h"
+
 #define _GNU_SOURCE
 
 #include 
@@ -32,6 +34,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -293,7 +296,11 @@ int main(int argc, char *argv[])
const struct test *t;
pid_t pid;
int total, pass;
+#ifdef HAVE_WAITID
siginfo_t info;
+#else
+   int status;
+#endif
 
if (isatty(fileno(stderr)))
is_atty = 1;
@@ -336,7 +343,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 +375,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++;
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH v2 6/9] core: define SO_PEERCRED if it's not defined

2019-02-08 Thread Leonid Bobrov
---
 src/wayland-os.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/wayland-os.h b/src/wayland-os.h
index 321e34d..28e3350 100644
--- a/src/wayland-os.h
+++ b/src/wayland-os.h
@@ -41,6 +41,9 @@ wl_os_queue_create_cloexec(void);
 int
 wl_os_accept_cloexec(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
 
+#ifndef SO_PEERCRED
+#define SO_PEERCRED LOCAL_PEERCRED
+#endif
 
 /*
  * The following are for wayland-os.c and the unit tests.
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH v2 5/9] core: support kqueue

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 Makefile.am  |   3 +-
 configure.ac |  19 +-
 doc/doxygen/Makefile.am  |   3 +-
 src/{event-loop.c => event-loop-epoll.c} |   4 +
 src/event-loop-kqueue.c  | 825 +++
 src/wayland-os.c |  47 +-
 src/wayland-os.h |   2 +-
 tests/os-wrappers-test.c |  55 +-
 8 files changed, 940 insertions(+), 18 deletions(-)
 rename src/{event-loop.c => event-loop-epoll.c} (99%)
 create mode 100644 src/event-loop-kqueue.c

diff --git a/Makefile.am b/Makefile.am
index 435957f..44b58c4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -76,7 +76,8 @@ libwayland_server_la_LDFLAGS = -version-info 1:0:1
 libwayland_server_la_SOURCES = \
src/wayland-server.c\
src/wayland-shm.c   \
-   src/event-loop.c
+   src/event-loop-epoll.c  \
+   src/event-loop-kqueue.c
 
 nodist_libwayland_server_la_SOURCES =  \
protocol/wayland-server-protocol.h  \
diff --git a/configure.ac b/configure.ac
index 9ca2331..8563968 100644
--- a/configure.ac
+++ b/configure.ac
@@ -65,6 +65,11 @@ 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
+
 # Replacement for /proc on BSD
 AC_CHECK_HEADERS([kvm.h])
 SAVE_LIBS="$LIBS"
@@ -128,12 +133,14 @@ 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 ]])
-   AC_CHECK_DECL(TFD_CLOEXEC,[],
- [AC_MSG_ERROR("TFD_CLOEXEC is needed to compile wayland 
libraries")],
- [[#include ]])
+   if test "x$ac_cv_header_sys_epoll_h" == "xyes"; then
+   AC_CHECK_DECL(SFD_CLOEXEC,[],
+ [AC_MSG_ERROR("SFD_CLOEXEC is needed to compile 
wayland libraries")],
+ [[#include ]])
+   AC_CHECK_DECL(TFD_CLOEXEC,[],
+ [AC_MSG_ERROR("TFD_CLOEXEC is needed to compile 
wayland libraries")],
+ [[#include ]])
+   fi
AC_CHECK_DECL(CLOCK_MONOTONIC,[],
  [AC_MSG_ERROR("CLOCK_MONOTONIC is needed to compile 
wayland libraries")],
  [[#include ]])
diff --git a/doc/doxygen/Makefile.am b/doc/doxygen/Makefile.am
index f8b0b3a..60bed53 100644
--- a/doc/doxygen/Makefile.am
+++ b/doc/doxygen/Makefile.am
@@ -19,7 +19,8 @@ scanned_src_files_Client =\
 
 scanned_src_files_Server = \
$(scanned_src_files_shared) \
-   $(top_srcdir)/src/event-loop.c  \
+   $(top_srcdir)/src/event-loop-epoll.c\
+   $(top_srcdir)/src/event-loop-kqueue.c   \
$(top_srcdir)/src/wayland-server.c  \
$(top_srcdir)/src/wayland-server.h  \
$(top_srcdir)/src/wayland-server-core.h \
diff --git a/src/event-loop.c b/src/event-loop-epoll.c
similarity index 99%
rename from src/event-loop.c
rename to src/event-loop-epoll.c
index eb2dce6..0242b86 100644
--- a/src/event-loop.c
+++ b/src/event-loop-epoll.c
@@ -23,6 +23,9 @@
  * SOFTWARE.
  */
 
+#include "config.h"
+
+#ifdef HAVE_SYS_EPOLL_H
 #include 
 #include 
 #include 
@@ -702,3 +705,4 @@ wl_event_loop_get_destroy_listener(struct wl_event_loop 
*loop,
 {
return wl_signal_get(&loop->destroy_signal, notify);
 }
+#endif
diff --git a/src/event-loop-kqueue.c b/src/event-loop-kqueue.c
new file mode 100644
index 000..5cb8592
--- /dev/null
+++ b/src/event-loop-kqueue.c
@@ -0,0 +1,825 @@
+/*
+ * 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, FITNES

[PATCH v2 4/9] tests: use *BSD replacement for /proc

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 Makefile.am  |  1 +
 configure.ac | 12 
 tests/test-helpers.c | 31 ++-
 3 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/Makefile.am b/Makefile.am
index 489f581..435957f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -215,6 +215,7 @@ noinst_LTLIBRARIES +=   \
libtest-helpers.la
 
 libtest_helpers_la_SOURCES = tests/test-helpers.c
+libtest_helpers_la_LIBADD = $(KVM_LIBS)
 
 libtest_runner_la_SOURCES =\
tests/test-runner.c \
diff --git a/configure.ac b/configure.ac
index f53408a..9ca2331 100644
--- a/configure.ac
+++ b/configure.ac
@@ -65,6 +65,18 @@ AC_SUBST(GCC_CFLAGS)
 AC_CHECK_HEADERS([sys/prctl.h])
 AC_CHECK_FUNCS([accept4 mkostemp posix_fallocate prctl])
 
+# Replacement for /proc on BSD
+AC_CHECK_HEADERS([kvm.h])
+SAVE_LIBS="$LIBS"
+LIBS=
+AC_CHECK_LIB([kvm], [kvm_getfiles])
+KVM_LIBS="$LIBS"
+LIBS="$SAVE_LIBS"
+AC_SUBST(KVM_LIBS)
+if test "x$ac_cv_header_kvm_h" != "x" && test "x$ac_cv_lib_kvm_kvm_getfiles" 
!= "x"; then
+   AC_DEFINE(USE_LIBKVM, 1, [use libkvm on BSD])
+fi
+
 # *BSD don't have libdl, but they have its functions
 SAVE_LIBS="$LIBS"
 LIBS=
diff --git a/tests/test-helpers.c b/tests/test-helpers.c
index b2189d8..4b90a10 100644
--- a/tests/test-helpers.c
+++ b/tests/test-helpers.c
@@ -25,9 +25,18 @@
 
 #include "config.h"
 
-#include 
+#ifdef USE_LIBKVM
+#include 
+#include 
+#include 
+#include 
+#include 
+#else
 #include 
 #include 
+#endif
+
+#include 
 #include 
 #include 
 #include 
@@ -43,6 +52,25 @@
 int
 count_open_fds(void)
 {
+#ifdef USE_LIBKVM
+   /* Use BSD-specific kernel memory interface */
+
+   struct kinfo_file *kif;
+   kvm_t *kd;
+   int count;
+   char errstr[_POSIX2_LINE_MAX];
+
+   kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY|KVM_NO_FILES, errstr);
+   assert(kd != NULL);
+   kif = kvm_getfiles(kd, KERN_FILE_BYPID, getpid(), sizeof(struct 
kinfo_file), &count);
+   assert(kif != NULL);
+
+   /* KVM library frees memory on itself */
+   kvm_close(kd);
+   return count;
+#else
+   /* Use /proc filesystem. */
+
DIR *dir;
struct dirent *ent;
int count = 0;
@@ -62,6 +90,7 @@ count_open_fds(void)
closedir(dir);
 
return count;
+#endif
 }
 
 void
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH v2 2/9] configure: detect libdl and librt

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 Makefile.am  |  6 +++---
 configure.ac | 16 
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index f47d055..489f581 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -71,7 +71,7 @@ nodist_include_HEADERS =  \
protocol/wayland-client-protocol.h
 
 libwayland_server_la_CFLAGS = $(FFI_CFLAGS) $(AM_CFLAGS) -pthread
-libwayland_server_la_LIBADD = $(FFI_LIBS) libwayland-private.la 
libwayland-util.la -lrt -lm
+libwayland_server_la_LIBADD = $(FFI_LIBS) libwayland-private.la 
libwayland-util.la $(RT_LIBS) -lm
 libwayland_server_la_LDFLAGS = -version-info 1:0:1
 libwayland_server_la_SOURCES = \
src/wayland-server.c\
@@ -83,7 +83,7 @@ nodist_libwayland_server_la_SOURCES = \
protocol/wayland-protocol.c
 
 libwayland_client_la_CFLAGS = $(FFI_CFLAGS) $(AM_CFLAGS) -pthread
-libwayland_client_la_LIBADD = $(FFI_LIBS) libwayland-private.la 
libwayland-util.la -lrt -lm
+libwayland_client_la_LIBADD = $(FFI_LIBS) libwayland-private.la 
libwayland-util.la $(RT_LIBS) -lm
 libwayland_client_la_LDFLAGS = -version-info 3:0:3
 libwayland_client_la_SOURCES = \
src/wayland-client.c
@@ -227,7 +227,7 @@ libtest_runner_la_LIBADD =  \
libwayland-client.la\
libwayland-server.la\
libtest-helpers.la  \
-   -lrt -ldl $(FFI_LIBS)
+   $(RT_LIBS) $(DL_LIBS) $(FFI_LIBS)
 
 array_test_SOURCES = tests/array-test.c
 array_test_LDADD = libtest-runner.la
diff --git a/configure.ac b/configure.ac
index 18fb649..f53408a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -65,6 +65,22 @@ AC_SUBST(GCC_CFLAGS)
 AC_CHECK_HEADERS([sys/prctl.h])
 AC_CHECK_FUNCS([accept4 mkostemp posix_fallocate prctl])
 
+# *BSD don't have libdl, but they have its functions
+SAVE_LIBS="$LIBS"
+LIBS=
+AC_CHECK_LIB([dl], [dlsym])
+DL_LIBS="$LIBS"
+LIBS="$SAVE_LIBS"
+AC_SUBST(DL_LIBS)
+
+# *BSD don't have librt, but they have its functions
+SAVE_LIBS="$LIBS"
+LIBS=
+AC_CHECK_LIB([rt], [clock_gettime])
+RT_LIBS="$LIBS"
+LIBS="$SAVE_LIBS"
+AC_SUBST(RT_LIBS)
+
 AC_ARG_ENABLE([libraries],
  [AC_HELP_STRING([--disable-libraries],
  [Disable compilation of wayland libraries])],
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH v2 9/9] tests: add OS-specific tracing to runner

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 configure.ac|  3 +++
 tests/test-runner.c | 22 +-
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 15535ff..40cbd08 100644
--- a/configure.ac
+++ b/configure.ac
@@ -101,6 +101,9 @@ RT_LIBS="$LIBS"
 LIBS="$SAVE_LIBS"
 AC_SUBST(RT_LIBS)
 
+# Defines __FreeBSD__ if we're on FreeBSD, same for other *BSD
+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])
diff --git a/tests/test-runner.c b/tests/test-runner.c
index 7fa72eb..4791092 100644
--- a/tests/test-runner.c
+++ b/tests/test-runner.c
@@ -40,13 +40,26 @@
 #include 
 #include 
 #include 
+#ifdef HAVE_SYS_PRCTL_H
 #include 
+#endif
+#ifdef HAVE_SYS_PARAM_H
+#include 
+#endif
 #ifndef PR_SET_PTRACER
 # define PR_SET_PTRACER 0x59616d61
 #endif
 
 #include "test-runner.h"
 
+extern const struct test __start_test_section, __stop_test_section;
+
+#ifndef __linux__
+#define PTRACE_ATTACH PT_ATTACH
+#define PTRACE_CONT PT_CONTINUE
+#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. */
@@ -232,6 +245,10 @@ stderr_reset_color(void)
 static int
 is_debugger_attached(void)
 {
+#ifdef __OpenBSD__
+   /* OpenBSD doesn't allow to trace parent process */
+   return 0;
+#else
int status;
int rc;
pid_t pid;
@@ -262,13 +279,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 */
+#ifdef HAVE_SYS_PRCTL_H
rc = prctl(PR_SET_PTRACER, pid);
if (rc != 0 && errno != EINVAL) {
/* An error prevents us from telling if a debugger is 
attached.
@@ -282,6 +300,7 @@ is_debugger_attached(void)
/* Signal to client that parent is ready by passing '+' 
*/
write(pipefd[1], "+", 1);
}
+#endif
close(pipefd[1]);
 
waitpid(pid, &status, 0);
@@ -289,6 +308,7 @@ is_debugger_attached(void)
}
 
return rc;
+#endif
 }
 
 int main(int argc, char *argv[])
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH v2 1/9] tests: fix main symbol duplication

2019-02-08 Thread Leonid Bobrov
So far I got these errors before patching:

libtool: link: cc -o .libs/headers-test -pthread -Wall -Wextra 
-Wno-unused-parameter -g -Wstrict-prototypes -Wmissing-prototypes 
-fvisibility=hidden -O2 -pipe tests/headers-test.o 
tests/headers-protocol-test.o tests/headers-protocol-core-test.o 
/tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a -L.libs 
-lwayland-client -lffi -lm -lwayland-server -lkvm -Wl,-rpath-link,/usr/local/lib
ld: error: duplicate symbol: main
>>> defined at headers-test.c:53 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/headers-test.c:53)
>>>tests/headers-test.o:(main)
>>> defined at test-runner.c:377 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/test-runner.c:377)
>>>test-runner.o:(.text+0x250) in archive 
>>> /tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a

libtool: link: cc -o .libs/exec-fd-leak-checker -pthread -Wall -Wextra 
-Wno-unused-parameter -g -Wstrict-prototypes -Wmissing-prototypes 
-fvisibility=hidden -O2 -pipe tests/exec-fd-leak-checker.o 
/tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a -L.libs 
-lwayland-client -lffi -lm -lwayland-server -lkvm -Wl,-rpath-link,/usr/local/lib
ld: error: duplicate symbol: main
>>> defined at exec-fd-leak-checker.c:57 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/exec-fd-leak-checker.c:57)
>>>tests/exec-fd-leak-checker.o:(main)
>>> defined at test-runner.c:377 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/test-runner.c:377)
>>>test-runner.o:(.text+0x250) in archive 
>>> /tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a

Makefile.am: error: object 'tests/test-helpers.$(OBJEXT)' created both with 
libtool and without

libtool: link: cc -o .libs/fixed-benchmark -pthread -Wall -Wextra 
-Wno-unused-parameter -g -Wstrict-prototypes -Wmissing-prototypes 
-fvisibility=hidden -O2 -pipe tests/fixed-benchmark.o 
/tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a -L.libs 
-lwayland-client -lffi -lm -lwayland-server -lkvm -Wl,-rpath-link,/usr/local/lib
ld: error: duplicate symbol: main
>>> defined at fixed-benchmark.c:100 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/fixed-benchmark.c:100)
>>>tests/fixed-benchmark.o:(main)
>>> defined at test-runner.c:377 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/test-runner.c:377)
>>>test-runner.o:(.text+0x250) in archive 
>>> /tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a

This commit fixes all of that.

Signed-off-by: Leonid Bobrov 
---
 Makefile.am | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 697c517..f47d055 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -210,12 +210,15 @@ noinst_PROGRAMS = \
exec-fd-leak-checker\
fixed-benchmark
 
-noinst_LTLIBRARIES += libtest-runner.la
+noinst_LTLIBRARIES +=  \
+   libtest-runner.la   \
+   libtest-helpers.la
+
+libtest_helpers_la_SOURCES = tests/test-helpers.c
 
 libtest_runner_la_SOURCES =\
tests/test-runner.c \
tests/test-runner.h \
-   tests/test-helpers.c\
tests/test-compositor.h \
tests/test-compositor.c
 libtest_runner_la_LIBADD = \
@@ -223,9 +226,9 @@ libtest_runner_la_LIBADD =  \
libwayland-util.la  \
libwayland-client.la\
libwayland-server.la\
+   libtest-helpers.la  \
-lrt -ldl $(FFI_LIBS)
 
-
 array_test_SOURCES = tests/array-test.c
 array_test_LDADD = libtest-runner.la
 client_test_SOURCES = tests/client-test.c
@@ -270,7 +273,6 @@ protocol_logger_test_LDADD = libtest-runner.la
 headers_test_SOURCES = tests/headers-test.c \
   tests/headers-protocol-test.c \
   tests/headers-protocol-core-test.c
-headers_test_LDADD = libtest-runner.la
 nodist_headers_test_SOURCES =  \
protocol/wayland-server-protocol-core.h \
protocol/wayland-client-protocol-core.h
@@ -280,13 +282,12 @@ cpp_compile_test_SOURCES = tests/cpp-compile-test.cpp
 endif
 
 fixed_benchmark_SOURCES = tests/fixed-benchmark.c
-fixed_benchmark_LDADD = libtest-runner.la
 
 os_wrappers_test_SOURCES = tests/os-wrappers-test.c
 os_wrappers_test_LDADD = libtest-runner.la
 
 exec_fd_leak_checker_SOURCES = tests/exec-fd-leak-checker.c
-exec_fd_leak_checker_LDADD = libtest-runner.la
+exec_fd_leak_checker_LDADD = libtest-helpers.la
 
 EXTRA_DIST += tests/scanner-test.sh\
protocol/tests.xml  \
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH v2 3/9] client: define EPROTO if it's not defined

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 src/wayland-client.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/src/wayland-client.h b/src/wayland-client.h
index 9f70fa3..690c446 100644
--- a/src/wayland-client.h
+++ b/src/wayland-client.h
@@ -39,4 +39,8 @@
 #include "wayland-client-core.h"
 #include "wayland-client-protocol.h"
 
+#ifndef EPROTO
+#define EPROTO ENOPROTOOPT
+#endif
+
 #endif
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH v2 8/9] server: add *BSD credentials support

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 configure.ac |  3 +++
 src/wayland-server.c | 35 +++
 src/wayland-shm.c| 10 ++
 3 files changed, 48 insertions(+)

diff --git a/configure.ac b/configure.ac
index 3c227a2..15535ff 100644
--- a/configure.ac
+++ b/configure.ac
@@ -70,6 +70,9 @@ if test "x$ac_cv_header_sys_epoll_h" != "xyes" && test 
"x$ac_cv_header_sys_event
AC_MSG_ERROR([Can't find sys/epoll.h or sys/event.h. Please ensure 
either epoll or kqueue is available.])
 fi
 
+# Credential support on BSD
+AC_CHECK_HEADERS([sys/ucred.h])
+
 # Replacement for /proc on BSD
 AC_CHECK_HEADERS([kvm.h])
 SAVE_LIBS="$LIBS"
diff --git a/src/wayland-server.c b/src/wayland-server.c
index 19f6a76..64d021f 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -23,8 +23,15 @@
  * SOFTWARE.
  */
 
+#include "config.h"
+
 #define _GNU_SOURCE
 
+#ifdef HAVE_SYS_UCRED_H
+#include 
+#include 
+#endif
+
 #include 
 #include 
 #include 
@@ -77,7 +84,11 @@ struct wl_client {
struct wl_list link;
struct wl_map objects;
struct wl_priv_signal destroy_signal;
+#ifdef HAVE_SYS_UCRED_H
+   struct xucred xucred;
+#else
struct ucred ucred;
+#endif
int error;
struct wl_priv_signal resource_created_signal;
 };
@@ -312,7 +323,11 @@ wl_resource_post_error(struct wl_resource *resource,
 static void
 destroy_client_with_error(struct wl_client *client, const char *reason)
 {
+#ifdef HAVE_SYS_UCRED_H
+   wl_log("%s (uid %u)\n", reason, client->xucred.cr_uid);
+#else
wl_log("%s (pid %u)\n", reason, client->ucred.pid);
+#endif
wl_client_destroy(client);
 }
 
@@ -526,10 +541,22 @@ wl_client_create(struct wl_display *display, int fd)
if (!client->source)
goto err_client;
 
+#ifdef HAVE_SYS_UCRED_H
+   len = sizeof client->xucred;
+   if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED,
+  &client->xucred, &len) < 0
+# ifdef XUCRED_VERSION
+  /* FreeBSD */
+  || client->xucred.cr_version != XUCRED_VERSION
+# endif
+ )
+   goto err_source;
+#else
len = sizeof client->ucred;
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED,
   &client->ucred, &len) < 0)
goto err_source;
+#endif
 
client->connection = wl_connection_create(fd);
if (client->connection == NULL)
@@ -583,12 +610,20 @@ 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
+   *pid = 0; /* FIXME: pid is not defined on BSD */
+   if (uid)
+   *uid = client->xucred.cr_uid;
+   if (gid)
+   *gid = client->xucred.cr_gid;
+#else
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
diff --git a/src/wayland-shm.c b/src/wayland-shm.c
index 4191231..6f2b1d8 100644
--- a/src/wayland-shm.c
+++ b/src/wayland-shm.c
@@ -28,6 +28,8 @@
  *
  */
 
+#include "config.h"
+
 #define _GNU_SOURCE
 
 #include 
@@ -59,6 +61,7 @@ struct wl_shm_pool {
char *data;
int32_t size;
int32_t new_size;
+   int fd;
 };
 
 struct wl_shm_buffer {
@@ -110,6 +113,9 @@ shm_pool_unref(struct wl_shm_pool *pool, bool external)
if (pool->internal_refcount + pool->external_refcount)
return;
 
+#ifdef HAVE_SYS_UCRED_H
+   close(pool->fd);
+#endif
munmap(pool->data, pool->size);
free(pool);
 }
@@ -284,7 +290,11 @@ shm_create_pool(struct wl_client *client, struct 
wl_resource *resource,
   "failed mmap fd %d: %m", fd);
goto err_free;
}
+#ifdef HAVE_SYS_UCRED_H
+   pool->fd = fd;
+#else
close(fd);
+#endif
 
pool->resource =
wl_resource_create(client, &wl_shm_pool_interface, 1, id);
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH 8/9] server: add *BSD credentials support

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 configure.ac |  3 +++
 src/wayland-server.c | 35 +++
 src/wayland-shm.c| 10 ++
 3 files changed, 48 insertions(+)

diff --git a/configure.ac b/configure.ac
index 3c227a2..15535ff 100644
--- a/configure.ac
+++ b/configure.ac
@@ -70,6 +70,9 @@ if test "x$ac_cv_header_sys_epoll_h" != "xyes" && test 
"x$ac_cv_header_sys_event
AC_MSG_ERROR([Can't find sys/epoll.h or sys/event.h. Please ensure 
either epoll or kqueue is available.])
 fi
 
+# Credential support on BSD
+AC_CHECK_HEADERS([sys/ucred.h])
+
 # Replacement for /proc on BSD
 AC_CHECK_HEADERS([kvm.h])
 SAVE_LIBS="$LIBS"
diff --git a/src/wayland-server.c b/src/wayland-server.c
index 19f6a76..64d021f 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -23,8 +23,15 @@
  * SOFTWARE.
  */
 
+#include "config.h"
+
 #define _GNU_SOURCE
 
+#ifdef HAVE_SYS_UCRED_H
+#include 
+#include 
+#endif
+
 #include 
 #include 
 #include 
@@ -77,7 +84,11 @@ struct wl_client {
struct wl_list link;
struct wl_map objects;
struct wl_priv_signal destroy_signal;
+#ifdef HAVE_SYS_UCRED_H
+   struct xucred xucred;
+#else
struct ucred ucred;
+#endif
int error;
struct wl_priv_signal resource_created_signal;
 };
@@ -312,7 +323,11 @@ wl_resource_post_error(struct wl_resource *resource,
 static void
 destroy_client_with_error(struct wl_client *client, const char *reason)
 {
+#ifdef HAVE_SYS_UCRED_H
+   wl_log("%s (uid %u)\n", reason, client->xucred.cr_uid);
+#else
wl_log("%s (pid %u)\n", reason, client->ucred.pid);
+#endif
wl_client_destroy(client);
 }
 
@@ -526,10 +541,22 @@ wl_client_create(struct wl_display *display, int fd)
if (!client->source)
goto err_client;
 
+#ifdef HAVE_SYS_UCRED_H
+   len = sizeof client->xucred;
+   if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED,
+  &client->xucred, &len) < 0
+# ifdef XUCRED_VERSION
+  /* FreeBSD */
+  || client->xucred.cr_version != XUCRED_VERSION
+# endif
+ )
+   goto err_source;
+#else
len = sizeof client->ucred;
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED,
   &client->ucred, &len) < 0)
goto err_source;
+#endif
 
client->connection = wl_connection_create(fd);
if (client->connection == NULL)
@@ -583,12 +610,20 @@ 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
+   *pid = 0; /* FIXME: pid is not defined on BSD */
+   if (uid)
+   *uid = client->xucred.cr_uid;
+   if (gid)
+   *gid = client->xucred.cr_gid;
+#else
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
diff --git a/src/wayland-shm.c b/src/wayland-shm.c
index 4191231..6f2b1d8 100644
--- a/src/wayland-shm.c
+++ b/src/wayland-shm.c
@@ -28,6 +28,8 @@
  *
  */
 
+#include "config.h"
+
 #define _GNU_SOURCE
 
 #include 
@@ -59,6 +61,7 @@ struct wl_shm_pool {
char *data;
int32_t size;
int32_t new_size;
+   int fd;
 };
 
 struct wl_shm_buffer {
@@ -110,6 +113,9 @@ shm_pool_unref(struct wl_shm_pool *pool, bool external)
if (pool->internal_refcount + pool->external_refcount)
return;
 
+#ifdef HAVE_SYS_UCRED_H
+   close(pool->fd);
+#endif
munmap(pool->data, pool->size);
free(pool);
 }
@@ -284,7 +290,11 @@ shm_create_pool(struct wl_client *client, struct 
wl_resource *resource,
   "failed mmap fd %d: %m", fd);
goto err_free;
}
+#ifdef HAVE_SYS_UCRED_H
+   pool->fd = fd;
+#else
close(fd);
+#endif
 
pool->resource =
wl_resource_create(client, &wl_shm_pool_interface, 1, id);
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH 1/9] tests: fix main symbol duplication

2019-02-08 Thread Leonid Bobrov
So far I got these errors before patching:

libtool: link: cc -o .libs/headers-test -pthread -Wall -Wextra 
-Wno-unused-parameter -g -Wstrict-prototypes -Wmissing-prototypes 
-fvisibility=hidden -O2 -pipe tests/headers-test.o 
tests/headers-protocol-test.o tests/headers-protocol-core-test.o 
/tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a -L.libs 
-lwayland-client -lffi -lm -lwayland-server -lkvm -Wl,-rpath-link,/usr/local/lib
ld: error: duplicate symbol: main
>>> defined at headers-test.c:53 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/headers-test.c:53)
>>>tests/headers-test.o:(main)
>>> defined at test-runner.c:377 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/test-runner.c:377)
>>>test-runner.o:(.text+0x250) in archive 
>>> /tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a

libtool: link: cc -o .libs/exec-fd-leak-checker -pthread -Wall -Wextra 
-Wno-unused-parameter -g -Wstrict-prototypes -Wmissing-prototypes 
-fvisibility=hidden -O2 -pipe tests/exec-fd-leak-checker.o 
/tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a -L.libs 
-lwayland-client -lffi -lm -lwayland-server -lkvm -Wl,-rpath-link,/usr/local/lib
ld: error: duplicate symbol: main
>>> defined at exec-fd-leak-checker.c:57 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/exec-fd-leak-checker.c:57)
>>>tests/exec-fd-leak-checker.o:(main)
>>> defined at test-runner.c:377 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/test-runner.c:377)
>>>test-runner.o:(.text+0x250) in archive 
>>> /tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a

Makefile.am: error: object 'tests/test-helpers.$(OBJEXT)' created both with 
libtool and without

libtool: link: cc -o .libs/fixed-benchmark -pthread -Wall -Wextra 
-Wno-unused-parameter -g -Wstrict-prototypes -Wmissing-prototypes 
-fvisibility=hidden -O2 -pipe tests/fixed-benchmark.o 
/tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a -L.libs 
-lwayland-client -lffi -lm -lwayland-server -lkvm -Wl,-rpath-link,/usr/local/lib
ld: error: duplicate symbol: main
>>> defined at fixed-benchmark.c:100 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/fixed-benchmark.c:100)
>>>tests/fixed-benchmark.o:(main)
>>> defined at test-runner.c:377 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/test-runner.c:377)
>>>test-runner.o:(.text+0x250) in archive 
>>> /tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a

This commit fixes all of that.

Signed-off-by: Leonid Bobrov 
---
 Makefile.am | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 697c517..cce4d73 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -210,12 +210,16 @@ noinst_PROGRAMS = \
exec-fd-leak-checker\
fixed-benchmark
 
-noinst_LTLIBRARIES += libtest-runner.la
+noinst_LTLIBRARIES +=  \
+   libtest-runner.la   \
+   libtest-helpers.la
+
+libtest_helpers_la_SOURCES = tests/test-helpers.c
+libtest_helpers_la_LIBADD = -lrt -ldl $(FFI_LIBS)
 
 libtest_runner_la_SOURCES =\
tests/test-runner.c \
tests/test-runner.h \
-   tests/test-helpers.c\
tests/test-compositor.h \
tests/test-compositor.c
 libtest_runner_la_LIBADD = \
@@ -223,8 +227,7 @@ libtest_runner_la_LIBADD =  \
libwayland-util.la  \
libwayland-client.la\
libwayland-server.la\
-   -lrt -ldl $(FFI_LIBS)
-
+   libtest-helpers.la
 
 array_test_SOURCES = tests/array-test.c
 array_test_LDADD = libtest-runner.la
@@ -270,7 +273,6 @@ protocol_logger_test_LDADD = libtest-runner.la
 headers_test_SOURCES = tests/headers-test.c \
   tests/headers-protocol-test.c \
   tests/headers-protocol-core-test.c
-headers_test_LDADD = libtest-runner.la
 nodist_headers_test_SOURCES =  \
protocol/wayland-server-protocol-core.h \
protocol/wayland-client-protocol-core.h
@@ -280,13 +282,12 @@ cpp_compile_test_SOURCES = tests/cpp-compile-test.cpp
 endif
 
 fixed_benchmark_SOURCES = tests/fixed-benchmark.c
-fixed_benchmark_LDADD = libtest-runner.la
 
 os_wrappers_test_SOURCES = tests/os-wrappers-test.c
 os_wrappers_test_LDADD = libtest-runner.la
 
 exec_fd_leak_checker_SOURCES = tests/exec-fd-leak-checker.c
-exec_fd_leak_checker_LDADD = libtest-runner.la
+exec_fd_leak_checker_LDADD = libtest-helpers.la
 
 EXTRA_DIST += tests/scanner-test.sh\
protocol/tests.xml  \
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH 9/9] tests: add OS-specific tracing to runner

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 configure.ac|  3 +++
 tests/test-runner.c | 22 +-
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 15535ff..40cbd08 100644
--- a/configure.ac
+++ b/configure.ac
@@ -101,6 +101,9 @@ RT_LIBS="$LIBS"
 LIBS="$SAVE_LIBS"
 AC_SUBST(RT_LIBS)
 
+# Defines __FreeBSD__ if we're on FreeBSD, same for other *BSD
+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])
diff --git a/tests/test-runner.c b/tests/test-runner.c
index 7fa72eb..4791092 100644
--- a/tests/test-runner.c
+++ b/tests/test-runner.c
@@ -40,13 +40,26 @@
 #include 
 #include 
 #include 
+#ifdef HAVE_SYS_PRCTL_H
 #include 
+#endif
+#ifdef HAVE_SYS_PARAM_H
+#include 
+#endif
 #ifndef PR_SET_PTRACER
 # define PR_SET_PTRACER 0x59616d61
 #endif
 
 #include "test-runner.h"
 
+extern const struct test __start_test_section, __stop_test_section;
+
+#ifndef __linux__
+#define PTRACE_ATTACH PT_ATTACH
+#define PTRACE_CONT PT_CONTINUE
+#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. */
@@ -232,6 +245,10 @@ stderr_reset_color(void)
 static int
 is_debugger_attached(void)
 {
+#ifdef __OpenBSD__
+   /* OpenBSD doesn't allow to trace parent process */
+   return 0;
+#else
int status;
int rc;
pid_t pid;
@@ -262,13 +279,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 */
+#ifdef HAVE_SYS_PRCTL_H
rc = prctl(PR_SET_PTRACER, pid);
if (rc != 0 && errno != EINVAL) {
/* An error prevents us from telling if a debugger is 
attached.
@@ -282,6 +300,7 @@ is_debugger_attached(void)
/* Signal to client that parent is ready by passing '+' 
*/
write(pipefd[1], "+", 1);
}
+#endif
close(pipefd[1]);
 
waitpid(pid, &status, 0);
@@ -289,6 +308,7 @@ is_debugger_attached(void)
}
 
return rc;
+#endif
 }
 
 int main(int argc, char *argv[])
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH 6/9] core: define SO_PEERCRED if it's not defined

2019-02-08 Thread Leonid Bobrov
---
 src/wayland-os.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/wayland-os.h b/src/wayland-os.h
index 321e34d..28e3350 100644
--- a/src/wayland-os.h
+++ b/src/wayland-os.h
@@ -41,6 +41,9 @@ wl_os_queue_create_cloexec(void);
 int
 wl_os_accept_cloexec(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
 
+#ifndef SO_PEERCRED
+#define SO_PEERCRED LOCAL_PEERCRED
+#endif
 
 /*
  * The following are for wayland-os.c and the unit tests.
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH 7/9] tests: support waitpid()

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 configure.ac|  4 
 tests/test-compositor.c | 25 +++--
 tests/test-runner.c | 29 -
 3 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/configure.ac b/configure.ac
index 8563968..3c227a2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -98,6 +98,10 @@ RT_LIBS="$LIBS"
 LIBS="$SAVE_LIBS"
 AC_SUBST(RT_LIBS)
 
+# 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])],
diff --git a/tests/test-compositor.c b/tests/test-compositor.c
index 72f6351..6e12630 100644
--- a/tests/test-compositor.c
+++ b/tests/test-compositor.c
@@ -23,6 +23,8 @@
  * SOFTWARE.
  */
 
+#include "config.h"
+
 #include 
 #include 
 #include 
@@ -86,8 +88,8 @@ get_socket_name(void)
static char retval[64];
 
gettimeofday(&tv, NULL);
-   snprintf(retval, sizeof retval, "wayland-test-%d-%ld%ld",
-getpid(), tv.tv_sec, tv.tv_usec);
+   snprintf(retval, sizeof retval, "wayland-test-%d-%lld%lld",
+getpid(), (long long)tv.tv_sec, (long long)tv.tv_usec);
 
return retval;
 }
@@ -97,10 +99,15 @@ handle_client_destroy(void *data)
 {
struct client_info *ci = data;
struct display *d;
+#ifdef HAVE_WAITID
siginfo_t status;
+#else
+   int istatus;
+#endif
 
d = ci->display;
 
+#ifdef HAVE_WAITID
assert(waitid(P_PID, ci->pid, &status, WEXITED) != -1);
 
switch (status.si_code) {
@@ -118,6 +125,20 @@ handle_client_destroy(void *data)
ci->exit_code = status.si_status;
break;
}
+#else
+   assert(waitpid(ci->pid, &istatus, WNOHANG) != -1);
+
+   if (WIFSIGNALED(istatus)) {
+   fprintf(stderr, "Client '%s' was killed by signal %d\n",
+   ci->name, WTERMSIG(istatus));
+   ci->exit_code = WEXITSTATUS(istatus);
+   } else if (WIFEXITED(istatus)) {
+   if (WEXITSTATUS(istatus) != EXIT_SUCCESS)
+   fprintf(stderr, "Client '%s' exited with code %d\n",
+   ci->name, WEXITSTATUS(istatus));
+   ci->exit_code = WEXITSTATUS(istatus);
+   }
+#endif
 
++d->clients_terminated_no;
if (d->clients_no == d->clients_terminated_no) {
diff --git a/tests/test-runner.c b/tests/test-runner.c
index 1487dc4..7fa72eb 100644
--- a/tests/test-runner.c
+++ b/tests/test-runner.c
@@ -23,6 +23,8 @@
  * SOFTWARE.
  */
 
+#include "config.h"
+
 #define _GNU_SOURCE
 
 #include 
@@ -32,6 +34,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -293,7 +296,11 @@ int main(int argc, char *argv[])
const struct test *t;
pid_t pid;
int total, pass;
+#ifdef HAVE_WAITID
siginfo_t info;
+#else
+   int status;
+#endif
 
if (isatty(fileno(stderr)))
is_atty = 1;
@@ -336,7 +343,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 +375,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++;
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH 3/9] client: define EPROTO if it's not defined

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 src/wayland-client.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/src/wayland-client.h b/src/wayland-client.h
index 9f70fa3..690c446 100644
--- a/src/wayland-client.h
+++ b/src/wayland-client.h
@@ -39,4 +39,8 @@
 #include "wayland-client-core.h"
 #include "wayland-client-protocol.h"
 
+#ifndef EPROTO
+#define EPROTO ENOPROTOOPT
+#endif
+
 #endif
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH 4/9] tests: use *BSD replacement for /proc

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 Makefile.am  |  1 +
 configure.ac | 12 
 tests/test-helpers.c | 31 ++-
 3 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/Makefile.am b/Makefile.am
index 489f581..435957f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -215,6 +215,7 @@ noinst_LTLIBRARIES +=   \
libtest-helpers.la
 
 libtest_helpers_la_SOURCES = tests/test-helpers.c
+libtest_helpers_la_LIBADD = $(KVM_LIBS)
 
 libtest_runner_la_SOURCES =\
tests/test-runner.c \
diff --git a/configure.ac b/configure.ac
index f53408a..9ca2331 100644
--- a/configure.ac
+++ b/configure.ac
@@ -65,6 +65,18 @@ AC_SUBST(GCC_CFLAGS)
 AC_CHECK_HEADERS([sys/prctl.h])
 AC_CHECK_FUNCS([accept4 mkostemp posix_fallocate prctl])
 
+# Replacement for /proc on BSD
+AC_CHECK_HEADERS([kvm.h])
+SAVE_LIBS="$LIBS"
+LIBS=
+AC_CHECK_LIB([kvm], [kvm_getfiles])
+KVM_LIBS="$LIBS"
+LIBS="$SAVE_LIBS"
+AC_SUBST(KVM_LIBS)
+if test "x$ac_cv_header_kvm_h" != "x" && test "x$ac_cv_lib_kvm_kvm_getfiles" 
!= "x"; then
+   AC_DEFINE(USE_LIBKVM, 1, [use libkvm on BSD])
+fi
+
 # *BSD don't have libdl, but they have its functions
 SAVE_LIBS="$LIBS"
 LIBS=
diff --git a/tests/test-helpers.c b/tests/test-helpers.c
index b2189d8..4b90a10 100644
--- a/tests/test-helpers.c
+++ b/tests/test-helpers.c
@@ -25,9 +25,18 @@
 
 #include "config.h"
 
-#include 
+#ifdef USE_LIBKVM
+#include 
+#include 
+#include 
+#include 
+#include 
+#else
 #include 
 #include 
+#endif
+
+#include 
 #include 
 #include 
 #include 
@@ -43,6 +52,25 @@
 int
 count_open_fds(void)
 {
+#ifdef USE_LIBKVM
+   /* Use BSD-specific kernel memory interface */
+
+   struct kinfo_file *kif;
+   kvm_t *kd;
+   int count;
+   char errstr[_POSIX2_LINE_MAX];
+
+   kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY|KVM_NO_FILES, errstr);
+   assert(kd != NULL);
+   kif = kvm_getfiles(kd, KERN_FILE_BYPID, getpid(), sizeof(struct 
kinfo_file), &count);
+   assert(kif != NULL);
+
+   /* KVM library frees memory on itself */
+   kvm_close(kd);
+   return count;
+#else
+   /* Use /proc filesystem. */
+
DIR *dir;
struct dirent *ent;
int count = 0;
@@ -62,6 +90,7 @@ count_open_fds(void)
closedir(dir);
 
return count;
+#endif
 }
 
 void
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH 5/9] core: support kqueue

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 Makefile.am  |   3 +-
 configure.ac |  19 +-
 doc/doxygen/Makefile.am  |   3 +-
 src/{event-loop.c => event-loop-epoll.c} |   4 +
 src/event-loop-kqueue.c  | 825 +++
 src/wayland-os.c |  47 +-
 src/wayland-os.h |   2 +-
 tests/os-wrappers-test.c |  55 +-
 8 files changed, 940 insertions(+), 18 deletions(-)
 rename src/{event-loop.c => event-loop-epoll.c} (99%)
 create mode 100644 src/event-loop-kqueue.c

diff --git a/Makefile.am b/Makefile.am
index 435957f..44b58c4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -76,7 +76,8 @@ libwayland_server_la_LDFLAGS = -version-info 1:0:1
 libwayland_server_la_SOURCES = \
src/wayland-server.c\
src/wayland-shm.c   \
-   src/event-loop.c
+   src/event-loop-epoll.c  \
+   src/event-loop-kqueue.c
 
 nodist_libwayland_server_la_SOURCES =  \
protocol/wayland-server-protocol.h  \
diff --git a/configure.ac b/configure.ac
index 9ca2331..8563968 100644
--- a/configure.ac
+++ b/configure.ac
@@ -65,6 +65,11 @@ 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
+
 # Replacement for /proc on BSD
 AC_CHECK_HEADERS([kvm.h])
 SAVE_LIBS="$LIBS"
@@ -128,12 +133,14 @@ 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 ]])
-   AC_CHECK_DECL(TFD_CLOEXEC,[],
- [AC_MSG_ERROR("TFD_CLOEXEC is needed to compile wayland 
libraries")],
- [[#include ]])
+   if test "x$ac_cv_header_sys_epoll_h" == "xyes"; then
+   AC_CHECK_DECL(SFD_CLOEXEC,[],
+ [AC_MSG_ERROR("SFD_CLOEXEC is needed to compile 
wayland libraries")],
+ [[#include ]])
+   AC_CHECK_DECL(TFD_CLOEXEC,[],
+ [AC_MSG_ERROR("TFD_CLOEXEC is needed to compile 
wayland libraries")],
+ [[#include ]])
+   fi
AC_CHECK_DECL(CLOCK_MONOTONIC,[],
  [AC_MSG_ERROR("CLOCK_MONOTONIC is needed to compile 
wayland libraries")],
  [[#include ]])
diff --git a/doc/doxygen/Makefile.am b/doc/doxygen/Makefile.am
index f8b0b3a..60bed53 100644
--- a/doc/doxygen/Makefile.am
+++ b/doc/doxygen/Makefile.am
@@ -19,7 +19,8 @@ scanned_src_files_Client =\
 
 scanned_src_files_Server = \
$(scanned_src_files_shared) \
-   $(top_srcdir)/src/event-loop.c  \
+   $(top_srcdir)/src/event-loop-epoll.c\
+   $(top_srcdir)/src/event-loop-kqueue.c   \
$(top_srcdir)/src/wayland-server.c  \
$(top_srcdir)/src/wayland-server.h  \
$(top_srcdir)/src/wayland-server-core.h \
diff --git a/src/event-loop.c b/src/event-loop-epoll.c
similarity index 99%
rename from src/event-loop.c
rename to src/event-loop-epoll.c
index eb2dce6..0242b86 100644
--- a/src/event-loop.c
+++ b/src/event-loop-epoll.c
@@ -23,6 +23,9 @@
  * SOFTWARE.
  */
 
+#include "config.h"
+
+#ifdef HAVE_SYS_EPOLL_H
 #include 
 #include 
 #include 
@@ -702,3 +705,4 @@ wl_event_loop_get_destroy_listener(struct wl_event_loop 
*loop,
 {
return wl_signal_get(&loop->destroy_signal, notify);
 }
+#endif
diff --git a/src/event-loop-kqueue.c b/src/event-loop-kqueue.c
new file mode 100644
index 000..5cb8592
--- /dev/null
+++ b/src/event-loop-kqueue.c
@@ -0,0 +1,825 @@
+/*
+ * 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, FITNES

[PATCH 2/9] configure: detect libdl and librt

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 Makefile.am  |  8 
 configure.ac | 16 
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index cce4d73..489f581 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -71,7 +71,7 @@ nodist_include_HEADERS =  \
protocol/wayland-client-protocol.h
 
 libwayland_server_la_CFLAGS = $(FFI_CFLAGS) $(AM_CFLAGS) -pthread
-libwayland_server_la_LIBADD = $(FFI_LIBS) libwayland-private.la 
libwayland-util.la -lrt -lm
+libwayland_server_la_LIBADD = $(FFI_LIBS) libwayland-private.la 
libwayland-util.la $(RT_LIBS) -lm
 libwayland_server_la_LDFLAGS = -version-info 1:0:1
 libwayland_server_la_SOURCES = \
src/wayland-server.c\
@@ -83,7 +83,7 @@ nodist_libwayland_server_la_SOURCES = \
protocol/wayland-protocol.c
 
 libwayland_client_la_CFLAGS = $(FFI_CFLAGS) $(AM_CFLAGS) -pthread
-libwayland_client_la_LIBADD = $(FFI_LIBS) libwayland-private.la 
libwayland-util.la -lrt -lm
+libwayland_client_la_LIBADD = $(FFI_LIBS) libwayland-private.la 
libwayland-util.la $(RT_LIBS) -lm
 libwayland_client_la_LDFLAGS = -version-info 3:0:3
 libwayland_client_la_SOURCES = \
src/wayland-client.c
@@ -215,7 +215,6 @@ noinst_LTLIBRARIES +=   \
libtest-helpers.la
 
 libtest_helpers_la_SOURCES = tests/test-helpers.c
-libtest_helpers_la_LIBADD = -lrt -ldl $(FFI_LIBS)
 
 libtest_runner_la_SOURCES =\
tests/test-runner.c \
@@ -227,7 +226,8 @@ libtest_runner_la_LIBADD =  \
libwayland-util.la  \
libwayland-client.la\
libwayland-server.la\
-   libtest-helpers.la
+   libtest-helpers.la  \
+   $(RT_LIBS) $(DL_LIBS) $(FFI_LIBS)
 
 array_test_SOURCES = tests/array-test.c
 array_test_LDADD = libtest-runner.la
diff --git a/configure.ac b/configure.ac
index 18fb649..f53408a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -65,6 +65,22 @@ AC_SUBST(GCC_CFLAGS)
 AC_CHECK_HEADERS([sys/prctl.h])
 AC_CHECK_FUNCS([accept4 mkostemp posix_fallocate prctl])
 
+# *BSD don't have libdl, but they have its functions
+SAVE_LIBS="$LIBS"
+LIBS=
+AC_CHECK_LIB([dl], [dlsym])
+DL_LIBS="$LIBS"
+LIBS="$SAVE_LIBS"
+AC_SUBST(DL_LIBS)
+
+# *BSD don't have librt, but they have its functions
+SAVE_LIBS="$LIBS"
+LIBS=
+AC_CHECK_LIB([rt], [clock_gettime])
+RT_LIBS="$LIBS"
+LIBS="$SAVE_LIBS"
+AC_SUBST(RT_LIBS)
+
 AC_ARG_ENABLE([libraries],
  [AC_HELP_STRING([--disable-libraries],
  [Disable compilation of wayland libraries])],
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH 4/6] tests: use *BSD replacement for /proc

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 Makefile.am  |  3 ++-
 configure.ac | 12 
 tests/test-helpers.c | 31 ++-
 3 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 489f581..8a6fa6e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -227,7 +227,8 @@ libtest_runner_la_LIBADD =  \
libwayland-client.la\
libwayland-server.la\
libtest-helpers.la  \
-   $(RT_LIBS) $(DL_LIBS) $(FFI_LIBS)
+   $(RT_LIBS) $(DL_LIBS)   \
+   $(FFI_LIBS) $(KVM_LIBS)
 
 array_test_SOURCES = tests/array-test.c
 array_test_LDADD = libtest-runner.la
diff --git a/configure.ac b/configure.ac
index f53408a..9ca2331 100644
--- a/configure.ac
+++ b/configure.ac
@@ -65,6 +65,18 @@ AC_SUBST(GCC_CFLAGS)
 AC_CHECK_HEADERS([sys/prctl.h])
 AC_CHECK_FUNCS([accept4 mkostemp posix_fallocate prctl])
 
+# Replacement for /proc on BSD
+AC_CHECK_HEADERS([kvm.h])
+SAVE_LIBS="$LIBS"
+LIBS=
+AC_CHECK_LIB([kvm], [kvm_getfiles])
+KVM_LIBS="$LIBS"
+LIBS="$SAVE_LIBS"
+AC_SUBST(KVM_LIBS)
+if test "x$ac_cv_header_kvm_h" != "x" && test "x$ac_cv_lib_kvm_kvm_getfiles" 
!= "x"; then
+   AC_DEFINE(USE_LIBKVM, 1, [use libkvm on BSD])
+fi
+
 # *BSD don't have libdl, but they have its functions
 SAVE_LIBS="$LIBS"
 LIBS=
diff --git a/tests/test-helpers.c b/tests/test-helpers.c
index b2189d8..4b90a10 100644
--- a/tests/test-helpers.c
+++ b/tests/test-helpers.c
@@ -25,9 +25,18 @@
 
 #include "config.h"
 
-#include 
+#ifdef USE_LIBKVM
+#include 
+#include 
+#include 
+#include 
+#include 
+#else
 #include 
 #include 
+#endif
+
+#include 
 #include 
 #include 
 #include 
@@ -43,6 +52,25 @@
 int
 count_open_fds(void)
 {
+#ifdef USE_LIBKVM
+   /* Use BSD-specific kernel memory interface */
+
+   struct kinfo_file *kif;
+   kvm_t *kd;
+   int count;
+   char errstr[_POSIX2_LINE_MAX];
+
+   kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY|KVM_NO_FILES, errstr);
+   assert(kd != NULL);
+   kif = kvm_getfiles(kd, KERN_FILE_BYPID, getpid(), sizeof(struct 
kinfo_file), &count);
+   assert(kif != NULL);
+
+   /* KVM library frees memory on itself */
+   kvm_close(kd);
+   return count;
+#else
+   /* Use /proc filesystem. */
+
DIR *dir;
struct dirent *ent;
int count = 0;
@@ -62,6 +90,7 @@ count_open_fds(void)
closedir(dir);
 
return count;
+#endif
 }
 
 void
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH 6/6] core: define SO_PEERCRED if it's not defined

2019-02-08 Thread Leonid Bobrov
---
 src/wayland-os.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/wayland-os.h b/src/wayland-os.h
index 321e34d..28e3350 100644
--- a/src/wayland-os.h
+++ b/src/wayland-os.h
@@ -41,6 +41,9 @@ wl_os_queue_create_cloexec(void);
 int
 wl_os_accept_cloexec(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
 
+#ifndef SO_PEERCRED
+#define SO_PEERCRED LOCAL_PEERCRED
+#endif
 
 /*
  * The following are for wayland-os.c and the unit tests.
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH 2/6] configure: detect libdl and librt

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 Makefile.am  |  8 
 configure.ac | 16 
 2 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index cce4d73..489f581 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -71,7 +71,7 @@ nodist_include_HEADERS =  \
protocol/wayland-client-protocol.h
 
 libwayland_server_la_CFLAGS = $(FFI_CFLAGS) $(AM_CFLAGS) -pthread
-libwayland_server_la_LIBADD = $(FFI_LIBS) libwayland-private.la 
libwayland-util.la -lrt -lm
+libwayland_server_la_LIBADD = $(FFI_LIBS) libwayland-private.la 
libwayland-util.la $(RT_LIBS) -lm
 libwayland_server_la_LDFLAGS = -version-info 1:0:1
 libwayland_server_la_SOURCES = \
src/wayland-server.c\
@@ -83,7 +83,7 @@ nodist_libwayland_server_la_SOURCES = \
protocol/wayland-protocol.c
 
 libwayland_client_la_CFLAGS = $(FFI_CFLAGS) $(AM_CFLAGS) -pthread
-libwayland_client_la_LIBADD = $(FFI_LIBS) libwayland-private.la 
libwayland-util.la -lrt -lm
+libwayland_client_la_LIBADD = $(FFI_LIBS) libwayland-private.la 
libwayland-util.la $(RT_LIBS) -lm
 libwayland_client_la_LDFLAGS = -version-info 3:0:3
 libwayland_client_la_SOURCES = \
src/wayland-client.c
@@ -215,7 +215,6 @@ noinst_LTLIBRARIES +=   \
libtest-helpers.la
 
 libtest_helpers_la_SOURCES = tests/test-helpers.c
-libtest_helpers_la_LIBADD = -lrt -ldl $(FFI_LIBS)
 
 libtest_runner_la_SOURCES =\
tests/test-runner.c \
@@ -227,7 +226,8 @@ libtest_runner_la_LIBADD =  \
libwayland-util.la  \
libwayland-client.la\
libwayland-server.la\
-   libtest-helpers.la
+   libtest-helpers.la  \
+   $(RT_LIBS) $(DL_LIBS) $(FFI_LIBS)
 
 array_test_SOURCES = tests/array-test.c
 array_test_LDADD = libtest-runner.la
diff --git a/configure.ac b/configure.ac
index 18fb649..f53408a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -65,6 +65,22 @@ AC_SUBST(GCC_CFLAGS)
 AC_CHECK_HEADERS([sys/prctl.h])
 AC_CHECK_FUNCS([accept4 mkostemp posix_fallocate prctl])
 
+# *BSD don't have libdl, but they have its functions
+SAVE_LIBS="$LIBS"
+LIBS=
+AC_CHECK_LIB([dl], [dlsym])
+DL_LIBS="$LIBS"
+LIBS="$SAVE_LIBS"
+AC_SUBST(DL_LIBS)
+
+# *BSD don't have librt, but they have its functions
+SAVE_LIBS="$LIBS"
+LIBS=
+AC_CHECK_LIB([rt], [clock_gettime])
+RT_LIBS="$LIBS"
+LIBS="$SAVE_LIBS"
+AC_SUBST(RT_LIBS)
+
 AC_ARG_ENABLE([libraries],
  [AC_HELP_STRING([--disable-libraries],
  [Disable compilation of wayland libraries])],
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH 3/6] client: define EPROTO if it's not defined

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 src/wayland-client.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/src/wayland-client.h b/src/wayland-client.h
index 9f70fa3..690c446 100644
--- a/src/wayland-client.h
+++ b/src/wayland-client.h
@@ -39,4 +39,8 @@
 #include "wayland-client-core.h"
 #include "wayland-client-protocol.h"
 
+#ifndef EPROTO
+#define EPROTO ENOPROTOOPT
+#endif
+
 #endif
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH 5/6] core: support kqueue

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 Makefile.am  |   3 +-
 configure.ac |  19 +-
 doc/doxygen/Makefile.am  |   3 +-
 src/{event-loop.c => event-loop-epoll.c} |   4 +
 src/event-loop-kqueue.c  | 825 +++
 src/wayland-os.c |  47 +-
 src/wayland-os.h |   2 +-
 tests/os-wrappers-test.c |  55 +-
 8 files changed, 940 insertions(+), 18 deletions(-)
 rename src/{event-loop.c => event-loop-epoll.c} (99%)
 create mode 100644 src/event-loop-kqueue.c

diff --git a/Makefile.am b/Makefile.am
index 8a6fa6e..0512b7f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -76,7 +76,8 @@ libwayland_server_la_LDFLAGS = -version-info 1:0:1
 libwayland_server_la_SOURCES = \
src/wayland-server.c\
src/wayland-shm.c   \
-   src/event-loop.c
+   src/event-loop-epoll.c  \
+   src/event-loop-kqueue.c
 
 nodist_libwayland_server_la_SOURCES =  \
protocol/wayland-server-protocol.h  \
diff --git a/configure.ac b/configure.ac
index 9ca2331..8563968 100644
--- a/configure.ac
+++ b/configure.ac
@@ -65,6 +65,11 @@ 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
+
 # Replacement for /proc on BSD
 AC_CHECK_HEADERS([kvm.h])
 SAVE_LIBS="$LIBS"
@@ -128,12 +133,14 @@ 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 ]])
-   AC_CHECK_DECL(TFD_CLOEXEC,[],
- [AC_MSG_ERROR("TFD_CLOEXEC is needed to compile wayland 
libraries")],
- [[#include ]])
+   if test "x$ac_cv_header_sys_epoll_h" == "xyes"; then
+   AC_CHECK_DECL(SFD_CLOEXEC,[],
+ [AC_MSG_ERROR("SFD_CLOEXEC is needed to compile 
wayland libraries")],
+ [[#include ]])
+   AC_CHECK_DECL(TFD_CLOEXEC,[],
+ [AC_MSG_ERROR("TFD_CLOEXEC is needed to compile 
wayland libraries")],
+ [[#include ]])
+   fi
AC_CHECK_DECL(CLOCK_MONOTONIC,[],
  [AC_MSG_ERROR("CLOCK_MONOTONIC is needed to compile 
wayland libraries")],
  [[#include ]])
diff --git a/doc/doxygen/Makefile.am b/doc/doxygen/Makefile.am
index f8b0b3a..60bed53 100644
--- a/doc/doxygen/Makefile.am
+++ b/doc/doxygen/Makefile.am
@@ -19,7 +19,8 @@ scanned_src_files_Client =\
 
 scanned_src_files_Server = \
$(scanned_src_files_shared) \
-   $(top_srcdir)/src/event-loop.c  \
+   $(top_srcdir)/src/event-loop-epoll.c\
+   $(top_srcdir)/src/event-loop-kqueue.c   \
$(top_srcdir)/src/wayland-server.c  \
$(top_srcdir)/src/wayland-server.h  \
$(top_srcdir)/src/wayland-server-core.h \
diff --git a/src/event-loop.c b/src/event-loop-epoll.c
similarity index 99%
rename from src/event-loop.c
rename to src/event-loop-epoll.c
index eb2dce6..0242b86 100644
--- a/src/event-loop.c
+++ b/src/event-loop-epoll.c
@@ -23,6 +23,9 @@
  * SOFTWARE.
  */
 
+#include "config.h"
+
+#ifdef HAVE_SYS_EPOLL_H
 #include 
 #include 
 #include 
@@ -702,3 +705,4 @@ wl_event_loop_get_destroy_listener(struct wl_event_loop 
*loop,
 {
return wl_signal_get(&loop->destroy_signal, notify);
 }
+#endif
diff --git a/src/event-loop-kqueue.c b/src/event-loop-kqueue.c
new file mode 100644
index 000..5cb8592
--- /dev/null
+++ b/src/event-loop-kqueue.c
@@ -0,0 +1,825 @@
+/*
+ * 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, FITNES

[PATCH 1/6] tests: fix main symbol duplication

2019-02-08 Thread Leonid Bobrov
So far I got these errors before patching:

libtool: link: cc -o .libs/headers-test -pthread -Wall -Wextra 
-Wno-unused-parameter -g -Wstrict-prototypes -Wmissing-prototypes 
-fvisibility=hidden -O2 -pipe tests/headers-test.o 
tests/headers-protocol-test.o tests/headers-protocol-core-test.o 
/tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a -L.libs 
-lwayland-client -lffi -lm -lwayland-server -lkvm -Wl,-rpath-link,/usr/local/lib
ld: error: duplicate symbol: main
>>> defined at headers-test.c:53 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/headers-test.c:53)
>>>tests/headers-test.o:(main)
>>> defined at test-runner.c:377 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/test-runner.c:377)
>>>test-runner.o:(.text+0x250) in archive 
>>> /tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a

libtool: link: cc -o .libs/exec-fd-leak-checker -pthread -Wall -Wextra 
-Wno-unused-parameter -g -Wstrict-prototypes -Wmissing-prototypes 
-fvisibility=hidden -O2 -pipe tests/exec-fd-leak-checker.o 
/tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a -L.libs 
-lwayland-client -lffi -lm -lwayland-server -lkvm -Wl,-rpath-link,/usr/local/lib
ld: error: duplicate symbol: main
>>> defined at exec-fd-leak-checker.c:57 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/exec-fd-leak-checker.c:57)
>>>tests/exec-fd-leak-checker.o:(main)
>>> defined at test-runner.c:377 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/test-runner.c:377)
>>>test-runner.o:(.text+0x250) in archive 
>>> /tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a

Makefile.am: error: object 'tests/test-helpers.$(OBJEXT)' created both with 
libtool and without

libtool: link: cc -o .libs/fixed-benchmark -pthread -Wall -Wextra 
-Wno-unused-parameter -g -Wstrict-prototypes -Wmissing-prototypes 
-fvisibility=hidden -O2 -pipe tests/fixed-benchmark.o 
/tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a -L.libs 
-lwayland-client -lffi -lm -lwayland-server -lkvm -Wl,-rpath-link,/usr/local/lib
ld: error: duplicate symbol: main
>>> defined at fixed-benchmark.c:100 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/fixed-benchmark.c:100)
>>>tests/fixed-benchmark.o:(main)
>>> defined at test-runner.c:377 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/test-runner.c:377)
>>>test-runner.o:(.text+0x250) in archive 
>>> /tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a

This commit fixes all of that.

Signed-off-by: Leonid Bobrov 
---
 Makefile.am | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 697c517..cce4d73 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -210,12 +210,16 @@ noinst_PROGRAMS = \
exec-fd-leak-checker\
fixed-benchmark
 
-noinst_LTLIBRARIES += libtest-runner.la
+noinst_LTLIBRARIES +=  \
+   libtest-runner.la   \
+   libtest-helpers.la
+
+libtest_helpers_la_SOURCES = tests/test-helpers.c
+libtest_helpers_la_LIBADD = -lrt -ldl $(FFI_LIBS)
 
 libtest_runner_la_SOURCES =\
tests/test-runner.c \
tests/test-runner.h \
-   tests/test-helpers.c\
tests/test-compositor.h \
tests/test-compositor.c
 libtest_runner_la_LIBADD = \
@@ -223,8 +227,7 @@ libtest_runner_la_LIBADD =  \
libwayland-util.la  \
libwayland-client.la\
libwayland-server.la\
-   -lrt -ldl $(FFI_LIBS)
-
+   libtest-helpers.la
 
 array_test_SOURCES = tests/array-test.c
 array_test_LDADD = libtest-runner.la
@@ -270,7 +273,6 @@ protocol_logger_test_LDADD = libtest-runner.la
 headers_test_SOURCES = tests/headers-test.c \
   tests/headers-protocol-test.c \
   tests/headers-protocol-core-test.c
-headers_test_LDADD = libtest-runner.la
 nodist_headers_test_SOURCES =  \
protocol/wayland-server-protocol-core.h \
protocol/wayland-client-protocol-core.h
@@ -280,13 +282,12 @@ cpp_compile_test_SOURCES = tests/cpp-compile-test.cpp
 endif
 
 fixed_benchmark_SOURCES = tests/fixed-benchmark.c
-fixed_benchmark_LDADD = libtest-runner.la
 
 os_wrappers_test_SOURCES = tests/os-wrappers-test.c
 os_wrappers_test_LDADD = libtest-runner.la
 
 exec_fd_leak_checker_SOURCES = tests/exec-fd-leak-checker.c
-exec_fd_leak_checker_LDADD = libtest-runner.la
+exec_fd_leak_checker_LDADD = libtest-helpers.la
 
 EXTRA_DIST += tests/scanner-test.sh\
protocol/tests.xml  \
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [PATCH 4/8] gitignore: ignore *.orig files generated by patch(1)

2019-02-08 Thread Pekka Paalanen
On Fri,  8 Feb 2019 15:13:37 +0200
Leonid Bobrov  wrote:

> Signed-off-by: Leonid Bobrov 
> ---
>  .gitignore | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/.gitignore b/.gitignore
> index eadea12..8d2c614 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -14,6 +14,7 @@
>  *.trs
>  *.tar.xz
>  *~
> +*.orig
>  *-test
>  .libs
>  .dirstamp

The build system does not use 'patch', so I don't think it can
generate .orig files even in an in-tree build. Was there a reason for
this patch?


Thanks,
pq


pgpGyh3P3VEFL.pgp
Description: OpenPGP digital signature
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [PATCH 3/8] server: add *BSD credentials support.

2019-02-08 Thread Pekka Paalanen
On Fri,  8 Feb 2019 15:13:36 +0200
Leonid Bobrov  wrote:

> Signed-off-by: Leonid Bobrov 
> ---
>  configure.ac |  3 ++
>  src/wayland-server.c | 46 ++
>  src/wayland-shm.c| 92 +++-
>  3 files changed, 140 insertions(+), 1 deletion(-)
> 
> diff --git a/configure.ac b/configure.ac
> index 912330e..d106a41 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -65,6 +65,9 @@ AC_SUBST(GCC_CFLAGS)
>  AC_CHECK_HEADERS([sys/prctl.h])
>  AC_CHECK_FUNCS([accept4 mkostemp posix_fallocate prctl])
>  
> +# Credential support on BSD
> +AC_CHECK_HEADERS([sys/ucred.h])
> +
>  # Replacement for /proc on BSD
>  AC_CHECK_HEADERS([kvm.h])
>  SAVE_LIBS="$LIBS"
> diff --git a/src/wayland-server.c b/src/wayland-server.c
> index 19f6a76..f4cdbf3 100644
> --- a/src/wayland-server.c
> +++ b/src/wayland-server.c
> @@ -25,6 +25,13 @@
>  
>  #define _GNU_SOURCE
>  
> +#include "../config.h"

Hi Leonid,

oh, we're missing config.h in lots of places. Adding that everywhere
should probably be a patch in front of the series. Usually that's just

#include "config.h"

with the build system setting the search paths appropriately.

> +
> +#ifdef HAVE_SYS_UCRED_H
> +#include 
> +#include 
> +#endif
> +
>  #include 
>  #include 
>  #include 
> @@ -77,7 +84,13 @@ struct wl_client {
>   struct wl_list link;
>   struct wl_map objects;
>   struct wl_priv_signal destroy_signal;
> +#ifdef HAVE_SYS_UCRED_H
> + /* BSD */
> + struct xucred xucred;
> +#else
> + /* Linux */
>   struct ucred ucred;
> +#endif

Maybe the above should be replaced with just pid, uid and gid fields,
to avoid the #ifdefs here and elsewhere.

>   int error;
>   struct wl_priv_signal resource_created_signal;
>  };
> @@ -312,7 +325,11 @@ wl_resource_post_error(struct wl_resource *resource,
>  static void
>  destroy_client_with_error(struct wl_client *client, const char *reason)
>  {
> +#ifdef HAVE_SYS_UCRED_H
> + wl_log("%s (uid %u)\n", reason, client->xucred.cr_uid);

Printing uid will be as useful as printing pid 0 always, since the user
is practically always the same. I'd drop this change.

> +#else
>   wl_log("%s (pid %u)\n", reason, client->ucred.pid);
> +#endif
>   wl_client_destroy(client);
>  }
>  
> @@ -526,10 +543,29 @@ wl_client_create(struct wl_display *display, int fd)
>   if (!client->source)
>   goto err_client;
>  
> +#ifndef SO_PEERCRED
> +/* FreeBSD */
> +# define SO_PEERCRED LOCAL_PEERCRED
> +#endif

This should go to wayland-os.h.

> +
> +#ifdef HAVE_SYS_UCRED_H
> + /* BSD */
> + len = sizeof client->xucred;
> + if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED,
> +&client->xucred, &len) < 0
> +# ifdef XUCRED_VERSION
> +/* FreeBSD */
> +|| client->xucred.cr_version != XUCRED_VERSION
> +# endif
> +   )
> + goto err_source;
> +#else
> + /* Linux */
>   len = sizeof client->ucred;
>   if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED,
>  &client->ucred, &len) < 0)
>   goto err_source;
> +#endif

Maybe wayland-os.c should have a wrapper for getsockopt(PEERCRED),
these #ifdefs are not nice.

>  
>   client->connection = wl_connection_create(fd);
>   if (client->connection == NULL)
> @@ -583,12 +619,22 @@ 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
> + /* BSD */
> + *pid = 0; /* FIXME: pid is not defined on BSD */
> + 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
> diff --git a/src/wayland-shm.c b/src/wayland-shm.c
> index 4191231..dbaf464 100644
> --- a/src/wayland-shm.c
> +++ b/src/wayland-shm.c
> @@ -30,6 +30,8 @@
>  
>  #define _GNU_SOURCE
>  
> +#include "../config.h"
> +
>  #include 
>  #include 
>  #include 
> @@ -59,6 +61,9 @@ struct wl_shm_pool {
>   char *data;
>   int32_t size;
>   int32_t new_size;
> +#ifdef HAVE_SYS_UCRED_H
> + int fd;

This field could be present unconditionally, and on Linux it would get
initialized to -1 and nothing more. Then you don't have to #ifdef the
close() of it either.

> +#endif
>  };
>  
>  struct wl_shm_buffer {
> @@ -76,15 +81,91 @@ struct wl_shm_sigbus_data {
>   int fallback_mapping_used;
>  };
>  
> +#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
> 

Re: [PATCH 2/8] tests: use *BSD replacement for /proc

2019-02-08 Thread Pekka Paalanen
On Fri,  8 Feb 2019 15:13:35 +0200
Leonid Bobrov  wrote:

> Signed-off-by: Leonid Bobrov 
> ---
>  Makefile.am  |  2 +-
>  configure.ac | 12 
>  tests/test-helpers.c | 33 -
>  3 files changed, 45 insertions(+), 2 deletions(-)
> 
> diff --git a/Makefile.am b/Makefile.am
> index cce4d73..52c7895 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -215,7 +215,7 @@ noinst_LTLIBRARIES += \
>   libtest-helpers.la
>  
>  libtest_helpers_la_SOURCES = tests/test-helpers.c
> -libtest_helpers_la_LIBADD = -lrt -ldl $(FFI_LIBS)
> +libtest_helpers_la_LIBADD = -lrt -ldl $(FFI_LIBS) $(KVM_LIBS)
>  
>  libtest_runner_la_SOURCES =  \
>   tests/test-runner.c \
> diff --git a/configure.ac b/configure.ac
> index 18fb649..912330e 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -65,6 +65,18 @@ AC_SUBST(GCC_CFLAGS)
>  AC_CHECK_HEADERS([sys/prctl.h])
>  AC_CHECK_FUNCS([accept4 mkostemp posix_fallocate prctl])
>  
> +# Replacement for /proc on BSD
> +AC_CHECK_HEADERS([kvm.h])
> +SAVE_LIBS="$LIBS"
> +LIBS=
> +AC_CHECK_LIB([kvm], [kvm_getfiles])
> +KVM_LIBS="$LIBS"
> +LIBS="$SAVE_LIBS"
> +AC_SUBST(KVM_LIBS)
> +if test "x$ac_cv_header_kvm_h" != "x" && test "x$ac_cv_lib_kvm_kvm_getfiles" 
> != "x"; then
> + AC_DEFINE(USE_LIBKVM, 1, [use libkvm on BSD])
> +fi

Hi Leonid,

My autoconf is getting rusty, but this looks ok to me.

> +
>  AC_ARG_ENABLE([libraries],
> [AC_HELP_STRING([--disable-libraries],
> [Disable compilation of wayland libraries])],
> diff --git a/tests/test-helpers.c b/tests/test-helpers.c
> index b2189d8..1c83e00 100644
> --- a/tests/test-helpers.c
> +++ b/tests/test-helpers.c
> @@ -25,9 +25,20 @@
>  
>  #include "config.h"
>  
> -#include 
> +#include "../config.h"

Why is this adding a second config.h include?

> +
> +#ifdef USE_LIBKVM
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#else
>  #include 
>  #include 
> +#endif
> +
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -43,6 +54,25 @@
>  int
>  count_open_fds(void)
>  {
> +#ifdef USE_LIBKVM
> + /* Use BSD-specific kernel memory interface */
> +
> + struct kinfo_file *kif;
> + kvm_t *kd;
> + int count;
> + char errstr[_POSIX2_LINE_MAX];
> +
> + kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY|KVM_NO_FILES, errstr);
> + assert(kd != NULL);
> + kif = kvm_getfiles(kd, KERN_FILE_BYPID, getpid(), sizeof(struct 
> kinfo_file), &count);
> + assert(kif != NULL);
> +
> + /* KVM library frees memory on itself */
> + kvm_close(kd);
> + return count;
> +#else
> + /* Use /proc filesystem. */
> +
>   DIR *dir;
>   struct dirent *ent;
>   int count = 0;
> @@ -62,6 +92,7 @@ count_open_fds(void)
>   closedir(dir);
>  
>   return count;
> +#endif
>  }
>  
>  void

I suppose this patch is fine. It's such a small chunk and there does
not seem to be anything else to special-case that would warrant a
new .c file or anything.

At the moment I do think this one needs to wait to see the CI support
materialize.


Thanks,
pq


pgpCqDwQhoI2B.pgp
Description: OpenPGP digital signature
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: [PATCH 1/8] tests: fix main symbol duplication

2019-02-08 Thread Pekka Paalanen
On Fri,  8 Feb 2019 15:13:34 +0200
Leonid Bobrov  wrote:

> So far I got these errors before patching:
> 
> libtool: link: cc -o .libs/headers-test -pthread -Wall -Wextra 
> -Wno-unused-parameter -g -Wstrict-prototypes -Wmissing-prototypes 
> -fvisibility=hidden -O2 -pipe tests/headers-test.o 
> tests/headers-protocol-test.o tests/headers-protocol-core-test.o 
> /tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a -L.libs 
> -lwayland-client -lffi -lm -lwayland-server -lkvm 
> -Wl,-rpath-link,/usr/local/lib
> ld: error: duplicate symbol: main
> >>> defined at headers-test.c:53 
> >>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/headers-test.c:53)
> >>>tests/headers-test.o:(main)
> >>> defined at test-runner.c:377 
> >>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/test-runner.c:377)
> >>>test-runner.o:(.text+0x250) in archive 
> >>> /tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a  
> 
> libtool: link: cc -o .libs/exec-fd-leak-checker -pthread -Wall -Wextra 
> -Wno-unused-parameter -g -Wstrict-prototypes -Wmissing-prototypes 
> -fvisibility=hidden -O2 -pipe tests/exec-fd-leak-checker.o 
> /tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a -L.libs 
> -lwayland-client -lffi -lm -lwayland-server -lkvm 
> -Wl,-rpath-link,/usr/local/lib
> ld: error: duplicate symbol: main
> >>> defined at exec-fd-leak-checker.c:57 
> >>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/exec-fd-leak-checker.c:57)
> >>>tests/exec-fd-leak-checker.o:(main)
> >>> defined at test-runner.c:377 
> >>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/test-runner.c:377)
> >>>test-runner.o:(.text+0x250) in archive 
> >>> /tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a  
> 
> Makefile.am: error: object 'tests/test-helpers.$(OBJEXT)' created both with 
> libtool and without
> 
> libtool: link: cc -o .libs/fixed-benchmark -pthread -Wall -Wextra 
> -Wno-unused-parameter -g -Wstrict-prototypes -Wmissing-prototypes 
> -fvisibility=hidden -O2 -pipe tests/fixed-benchmark.o 
> /tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a -L.libs 
> -lwayland-client -lffi -lm -lwayland-server -lkvm 
> -Wl,-rpath-link,/usr/local/lib
> ld: error: duplicate symbol: main
> >>> defined at fixed-benchmark.c:100 
> >>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/fixed-benchmark.c:100)
> >>>tests/fixed-benchmark.o:(main)
> >>> defined at test-runner.c:377 
> >>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/test-runner.c:377)
> >>>test-runner.o:(.text+0x250) in archive 
> >>> /tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a  
> 
> This commit fixes all of that.
> 
> Signed-off-by: Leonid Bobrov 
> ---
>  Makefile.am | 15 ---
>  1 file changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git a/Makefile.am b/Makefile.am
> index 697c517..cce4d73 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -210,12 +210,16 @@ noinst_PROGRAMS =   \
>   exec-fd-leak-checker\
>   fixed-benchmark
>  
> -noinst_LTLIBRARIES += libtest-runner.la
> +noinst_LTLIBRARIES +=\
> + libtest-runner.la   \
> + libtest-helpers.la
> +
> +libtest_helpers_la_SOURCES = tests/test-helpers.c

Hi Leonid,

this is a much better solution than I could have suggested.

> +libtest_helpers_la_LIBADD = -lrt -ldl $(FFI_LIBS)

It doesn't look like test-helpers.c needs these LIBADD at all, and
neither those that do not link to libtest_runner_la. How about keeping
these with libtest_runner_la instead?

Otherwise this patch looks good to me.


Thanks,
pq

>  
>  libtest_runner_la_SOURCES =  \
>   tests/test-runner.c \
>   tests/test-runner.h \
> - tests/test-helpers.c\
>   tests/test-compositor.h \
>   tests/test-compositor.c
>  libtest_runner_la_LIBADD =   \
> @@ -223,8 +227,7 @@ libtest_runner_la_LIBADD =\
>   libwayland-util.la  \
>   libwayland-client.la\
>   libwayland-server.la\
> - -lrt -ldl $(FFI_LIBS)
> -
> + libtest-helpers.la
>  
>  array_test_SOURCES = tests/array-test.c
>  array_test_LDADD = libtest-runner.la
> @@ -270,7 +273,6 @@ protocol_logger_test_LDADD = libtest-runner.la
>  headers_test_SOURCES = tests/headers-test.c \
>  tests/headers-protocol-test.c \
>  tests/headers-protocol-core-test.c
> -headers_test_LDADD = libtest-runner.la
>  nodist_headers_test_SOURCES =\
>   protocol/wayland-server-protocol-core.h \
>   protocol/wayland-client-protocol-core.h
> @@ -280,13 +282,12 @@ cpp_compile_test_SOURCES = tests/cpp-compile-test.cpp
>  endif
>  
>  fixed_benchmark_SOURCES = tests/fixed-benchmark.c
> -fixed_benchmark_LDADD = libtest-runner.la
>  
>  os_wrapp

[PATCH 8/8] configure: detect libdl and librt

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 Makefile.am  |  6 +++---
 configure.ac | 16 
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 426e20a..b973cbe 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -71,7 +71,7 @@ nodist_include_HEADERS =  \
protocol/wayland-client-protocol.h
 
 libwayland_server_la_CFLAGS = $(FFI_CFLAGS) $(AM_CFLAGS) -pthread
-libwayland_server_la_LIBADD = $(FFI_LIBS) libwayland-private.la 
libwayland-util.la -lrt -lm
+libwayland_server_la_LIBADD = $(FFI_LIBS) libwayland-private.la 
libwayland-util.la $(RT_LIBS) -lm
 libwayland_server_la_LDFLAGS = -version-info 1:0:1
 libwayland_server_la_SOURCES = \
src/wayland-server.c\
@@ -84,7 +84,7 @@ nodist_libwayland_server_la_SOURCES = \
protocol/wayland-protocol.c
 
 libwayland_client_la_CFLAGS = $(FFI_CFLAGS) $(AM_CFLAGS) -pthread
-libwayland_client_la_LIBADD = $(FFI_LIBS) libwayland-private.la 
libwayland-util.la -lrt -lm
+libwayland_client_la_LIBADD = $(FFI_LIBS) libwayland-private.la 
libwayland-util.la $(RT_LIBS) -lm
 libwayland_client_la_LDFLAGS = -version-info 3:0:3
 libwayland_client_la_SOURCES = \
src/wayland-client.c
@@ -216,7 +216,7 @@ noinst_LTLIBRARIES +=   \
libtest-helpers.la
 
 libtest_helpers_la_SOURCES = tests/test-helpers.c
-libtest_helpers_la_LIBADD = -lrt -ldl $(FFI_LIBS) $(KVM_LIBS)
+libtest_helpers_la_LIBADD = $(RT_LIBS) $(DL_LIBS) $(FFI_LIBS) $(KVM_LIBS)
 
 libtest_runner_la_SOURCES =\
tests/test-runner.c \
diff --git a/configure.ac b/configure.ac
index 1d1a25b..40cbd08 100644
--- a/configure.ac
+++ b/configure.ac
@@ -85,6 +85,22 @@ if test "x$ac_cv_header_kvm_h" != "x" && test 
"x$ac_cv_lib_kvm_kvm_getfiles" !=
AC_DEFINE(USE_LIBKVM, 1, [use libkvm on BSD])
 fi
 
+# *BSD don't have libdl, but they have its functions
+SAVE_LIBS="$LIBS"
+LIBS=
+AC_CHECK_LIB([dl], [dlsym])
+DL_LIBS="$LIBS"
+LIBS="$SAVE_LIBS"
+AC_SUBST(DL_LIBS)
+
+# *BSD don't have librt, but they have its functions
+SAVE_LIBS="$LIBS"
+LIBS=
+AC_CHECK_LIB([rt], [clock_gettime])
+RT_LIBS="$LIBS"
+LIBS="$SAVE_LIBS"
+AC_SUBST(RT_LIBS)
+
 # Defines __FreeBSD__ if we're on FreeBSD, same for other *BSD
 AC_CHECK_HEADERS([sys/param.h])
 
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH 5/8] core: support kqueue

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 Makefile.am  |   3 +-
 configure.ac |  19 +-
 doc/doxygen/Makefile.am  |   3 +-
 src/{event-loop.c => event-loop-epoll.c} |   4 +
 src/event-loop-kqueue.c  | 825 +++
 src/wayland-os.c |  47 +-
 src/wayland-os.h |   2 +-
 tests/os-wrappers-test.c |  55 +-
 8 files changed, 940 insertions(+), 18 deletions(-)
 rename src/{event-loop.c => event-loop-epoll.c} (99%)
 create mode 100644 src/event-loop-kqueue.c

diff --git a/Makefile.am b/Makefile.am
index 52c7895..426e20a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -76,7 +76,8 @@ libwayland_server_la_LDFLAGS = -version-info 1:0:1
 libwayland_server_la_SOURCES = \
src/wayland-server.c\
src/wayland-shm.c   \
-   src/event-loop.c
+   src/event-loop-epoll.c  \
+   src/event-loop-kqueue.c
 
 nodist_libwayland_server_la_SOURCES =  \
protocol/wayland-server-protocol.h  \
diff --git a/configure.ac b/configure.ac
index d106a41..941749d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -65,6 +65,11 @@ 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
+
 # Credential support on BSD
 AC_CHECK_HEADERS([sys/ucred.h])
 
@@ -115,12 +120,14 @@ 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 ]])
-   AC_CHECK_DECL(TFD_CLOEXEC,[],
- [AC_MSG_ERROR("TFD_CLOEXEC is needed to compile wayland 
libraries")],
- [[#include ]])
+   if test "x$ac_cv_header_sys_epoll_h" == "xyes"; then
+   AC_CHECK_DECL(SFD_CLOEXEC,[],
+ [AC_MSG_ERROR("SFD_CLOEXEC is needed to compile 
wayland libraries")],
+ [[#include ]])
+   AC_CHECK_DECL(TFD_CLOEXEC,[],
+ [AC_MSG_ERROR("TFD_CLOEXEC is needed to compile 
wayland libraries")],
+ [[#include ]])
+   fi
AC_CHECK_DECL(CLOCK_MONOTONIC,[],
  [AC_MSG_ERROR("CLOCK_MONOTONIC is needed to compile 
wayland libraries")],
  [[#include ]])
diff --git a/doc/doxygen/Makefile.am b/doc/doxygen/Makefile.am
index f8b0b3a..60bed53 100644
--- a/doc/doxygen/Makefile.am
+++ b/doc/doxygen/Makefile.am
@@ -19,7 +19,8 @@ scanned_src_files_Client =\
 
 scanned_src_files_Server = \
$(scanned_src_files_shared) \
-   $(top_srcdir)/src/event-loop.c  \
+   $(top_srcdir)/src/event-loop-epoll.c\
+   $(top_srcdir)/src/event-loop-kqueue.c   \
$(top_srcdir)/src/wayland-server.c  \
$(top_srcdir)/src/wayland-server.h  \
$(top_srcdir)/src/wayland-server-core.h \
diff --git a/src/event-loop.c b/src/event-loop-epoll.c
similarity index 99%
rename from src/event-loop.c
rename to src/event-loop-epoll.c
index eb2dce6..76cbfae 100644
--- a/src/event-loop.c
+++ b/src/event-loop-epoll.c
@@ -23,6 +23,9 @@
  * SOFTWARE.
  */
 
+#include "../config.h"
+
+#ifdef HAVE_SYS_EPOLL_H
 #include 
 #include 
 #include 
@@ -702,3 +705,4 @@ wl_event_loop_get_destroy_listener(struct wl_event_loop 
*loop,
 {
return wl_signal_get(&loop->destroy_signal, notify);
 }
+#endif
diff --git a/src/event-loop-kqueue.c b/src/event-loop-kqueue.c
new file mode 100644
index 000..2713416
--- /dev/null
+++ b/src/event-loop-kqueue.c
@@ -0,0 +1,825 @@
+/*
+ * 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 PAR

[PATCH 6/8] client: define EPROTO if it's not defined

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 src/wayland-client.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/src/wayland-client.h b/src/wayland-client.h
index 9f70fa3..524f79d 100644
--- a/src/wayland-client.h
+++ b/src/wayland-client.h
@@ -36,6 +36,10 @@
 #ifndef WAYLAND_CLIENT_H
 #define WAYLAND_CLIENT_H
 
+#ifndef EPROTO
+# define EPROTO ENOPROTOOPT
+#endif
+
 #include "wayland-client-core.h"
 #include "wayland-client-protocol.h"
 
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH 7/8] tests: support waitpid()

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 configure.ac|  7 ++
 tests/test-compositor.c | 23 +++--
 tests/test-runner.c | 55 ++---
 3 files changed, 80 insertions(+), 5 deletions(-)

diff --git a/configure.ac b/configure.ac
index 941749d..1d1a25b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -85,6 +85,13 @@ if test "x$ac_cv_header_kvm_h" != "x" && test 
"x$ac_cv_lib_kvm_kvm_getfiles" !=
AC_DEFINE(USE_LIBKVM, 1, [use libkvm on BSD])
 fi
 
+# Defines __FreeBSD__ if we're on FreeBSD, same for other *BSD
+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])],
diff --git a/tests/test-compositor.c b/tests/test-compositor.c
index 72f6351..27285ee 100644
--- a/tests/test-compositor.c
+++ b/tests/test-compositor.c
@@ -86,8 +86,8 @@ get_socket_name(void)
static char retval[64];
 
gettimeofday(&tv, NULL);
-   snprintf(retval, sizeof retval, "wayland-test-%d-%ld%ld",
-getpid(), tv.tv_sec, tv.tv_usec);
+   snprintf(retval, sizeof retval, "wayland-test-%d-%lld%lld",
+getpid(), (long long)tv.tv_sec, (long long)tv.tv_usec);
 
return retval;
 }
@@ -97,10 +97,15 @@ handle_client_destroy(void *data)
 {
struct client_info *ci = data;
struct display *d;
+#ifdef HAVE_WAITID
siginfo_t status;
+#else
+   int istatus;
+#endif
 
d = ci->display;
 
+#ifdef HAVE_WAITID
assert(waitid(P_PID, ci->pid, &status, WEXITED) != -1);
 
switch (status.si_code) {
@@ -118,6 +123,20 @@ handle_client_destroy(void *data)
ci->exit_code = status.si_status;
break;
}
+#else
+   assert(waitpid(ci->pid, &istatus, WNOHANG) != -1);
+
+   if (WIFSIGNALED(istatus)) {
+   fprintf(stderr, "Client '%s' was killed by signal %d\n",
+   ci->name, WTERMSIG(istatus));
+   ci->exit_code = WEXITSTATUS(istatus);
+   } else if (WIFEXITED(istatus)) {
+   if (WEXITSTATUS(istatus) != EXIT_SUCCESS)
+   fprintf(stderr, "Client '%s' exited with code %d\n",
+   ci->name, WEXITSTATUS(istatus));
+   ci->exit_code = WEXITSTATUS(istatus);
+   }
+#endif
 
++d->clients_terminated_no;
if (d->clients_no == d->clients_terminated_no) {
diff --git a/tests/test-runner.c b/tests/test-runner.c
index 1487dc4..2936a59 100644
--- a/tests/test-runner.c
+++ b/tests/test-runner.c
@@ -25,6 +25,12 @@
 
 #define _GNU_SOURCE
 
+#include "../config.h"
+
+#ifdef HAVE_SYS_PARAM_H
+#include 
+#endif
+
 #include 
 #include 
 #include 
@@ -32,18 +38,30 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#ifdef HAVE_SYS_PRCTL_H
 #include 
+#endif
 #ifndef PR_SET_PTRACER
 # define PR_SET_PTRACER 0x59616d61
 #endif
 
 #include "test-runner.h"
 
+extern const struct test __start_test_section, __stop_test_section;
+
+#ifndef __linux__
+/* XXX review ptrace() usage */
+#define PTRACE_ATTACH PT_ATTACH
+#define PTRACE_CONT PT_CONTINUE
+#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 +69,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 */
@@ -229,6 +247,10 @@ stderr_reset_color(void)
 static int
 is_debugger_attached(void)
 {
+#ifdef __OpenBSD__
+   /* OpenBSD doesn't allow to trace parent process */
+   return 0;
+#else
int status;
int rc;
pid_t pid;
@@ -239,6 +261,8 @@ is_debugger_attached(void)
return 0;
}
 
+
+// xxx start here
pid = fork();
if (pid == -1) {
perror("fork");
@@ -259,7 +283,7 @@ 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 {
@@ -286,6 +310,7 @@ is_debugger_attached(void)
}
 
return rc;
+#endif
 }
 
 int main(int argc, char *argv[])
@@ -293,7 +318,11 @@ int main(int argc, char *argv[])
const struct test *t;
pid_t pid;
int total, pass;
+#ifdef HAVE_W

[PATCH 4/8] gitignore: ignore *.orig files generated by patch(1)

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 .gitignore | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitignore b/.gitignore
index eadea12..8d2c614 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,6 +14,7 @@
 *.trs
 *.tar.xz
 *~
+*.orig
 *-test
 .libs
 .dirstamp
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH 3/8] server: add *BSD credentials support.

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 configure.ac |  3 ++
 src/wayland-server.c | 46 ++
 src/wayland-shm.c| 92 +++-
 3 files changed, 140 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 912330e..d106a41 100644
--- a/configure.ac
+++ b/configure.ac
@@ -65,6 +65,9 @@ AC_SUBST(GCC_CFLAGS)
 AC_CHECK_HEADERS([sys/prctl.h])
 AC_CHECK_FUNCS([accept4 mkostemp posix_fallocate prctl])
 
+# Credential support on BSD
+AC_CHECK_HEADERS([sys/ucred.h])
+
 # Replacement for /proc on BSD
 AC_CHECK_HEADERS([kvm.h])
 SAVE_LIBS="$LIBS"
diff --git a/src/wayland-server.c b/src/wayland-server.c
index 19f6a76..f4cdbf3 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -25,6 +25,13 @@
 
 #define _GNU_SOURCE
 
+#include "../config.h"
+
+#ifdef HAVE_SYS_UCRED_H
+#include 
+#include 
+#endif
+
 #include 
 #include 
 #include 
@@ -77,7 +84,13 @@ struct wl_client {
struct wl_list link;
struct wl_map objects;
struct wl_priv_signal destroy_signal;
+#ifdef HAVE_SYS_UCRED_H
+   /* BSD */
+   struct xucred xucred;
+#else
+   /* Linux */
struct ucred ucred;
+#endif
int error;
struct wl_priv_signal resource_created_signal;
 };
@@ -312,7 +325,11 @@ wl_resource_post_error(struct wl_resource *resource,
 static void
 destroy_client_with_error(struct wl_client *client, const char *reason)
 {
+#ifdef HAVE_SYS_UCRED_H
+   wl_log("%s (uid %u)\n", reason, client->xucred.cr_uid);
+#else
wl_log("%s (pid %u)\n", reason, client->ucred.pid);
+#endif
wl_client_destroy(client);
 }
 
@@ -526,10 +543,29 @@ wl_client_create(struct wl_display *display, int fd)
if (!client->source)
goto err_client;
 
+#ifndef SO_PEERCRED
+/* FreeBSD */
+# define SO_PEERCRED LOCAL_PEERCRED
+#endif
+
+#ifdef HAVE_SYS_UCRED_H
+   /* BSD */
+   len = sizeof client->xucred;
+   if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED,
+  &client->xucred, &len) < 0
+# ifdef XUCRED_VERSION
+  /* FreeBSD */
+  || client->xucred.cr_version != XUCRED_VERSION
+# endif
+ )
+   goto err_source;
+#else
+   /* Linux */
len = sizeof client->ucred;
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED,
   &client->ucred, &len) < 0)
goto err_source;
+#endif
 
client->connection = wl_connection_create(fd);
if (client->connection == NULL)
@@ -583,12 +619,22 @@ 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
+   /* BSD */
+   *pid = 0; /* FIXME: pid is not defined on BSD */
+   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
diff --git a/src/wayland-shm.c b/src/wayland-shm.c
index 4191231..dbaf464 100644
--- a/src/wayland-shm.c
+++ b/src/wayland-shm.c
@@ -30,6 +30,8 @@
 
 #define _GNU_SOURCE
 
+#include "../config.h"
+
 #include 
 #include 
 #include 
@@ -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,91 @@ struct wl_shm_sigbus_data {
int fallback_mapping_used;
 };
 
+#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);

[PATCH 2/8] tests: use *BSD replacement for /proc

2019-02-08 Thread Leonid Bobrov
Signed-off-by: Leonid Bobrov 
---
 Makefile.am  |  2 +-
 configure.ac | 12 
 tests/test-helpers.c | 33 -
 3 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index cce4d73..52c7895 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -215,7 +215,7 @@ noinst_LTLIBRARIES +=   \
libtest-helpers.la
 
 libtest_helpers_la_SOURCES = tests/test-helpers.c
-libtest_helpers_la_LIBADD = -lrt -ldl $(FFI_LIBS)
+libtest_helpers_la_LIBADD = -lrt -ldl $(FFI_LIBS) $(KVM_LIBS)
 
 libtest_runner_la_SOURCES =\
tests/test-runner.c \
diff --git a/configure.ac b/configure.ac
index 18fb649..912330e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -65,6 +65,18 @@ AC_SUBST(GCC_CFLAGS)
 AC_CHECK_HEADERS([sys/prctl.h])
 AC_CHECK_FUNCS([accept4 mkostemp posix_fallocate prctl])
 
+# Replacement for /proc on BSD
+AC_CHECK_HEADERS([kvm.h])
+SAVE_LIBS="$LIBS"
+LIBS=
+AC_CHECK_LIB([kvm], [kvm_getfiles])
+KVM_LIBS="$LIBS"
+LIBS="$SAVE_LIBS"
+AC_SUBST(KVM_LIBS)
+if test "x$ac_cv_header_kvm_h" != "x" && test "x$ac_cv_lib_kvm_kvm_getfiles" 
!= "x"; then
+   AC_DEFINE(USE_LIBKVM, 1, [use libkvm on BSD])
+fi
+
 AC_ARG_ENABLE([libraries],
  [AC_HELP_STRING([--disable-libraries],
  [Disable compilation of wayland libraries])],
diff --git a/tests/test-helpers.c b/tests/test-helpers.c
index b2189d8..1c83e00 100644
--- a/tests/test-helpers.c
+++ b/tests/test-helpers.c
@@ -25,9 +25,20 @@
 
 #include "config.h"
 
-#include 
+#include "../config.h"
+
+#ifdef USE_LIBKVM
+#include 
+#include 
+#include 
+#include 
+#include 
+#else
 #include 
 #include 
+#endif
+
+#include 
 #include 
 #include 
 #include 
@@ -43,6 +54,25 @@
 int
 count_open_fds(void)
 {
+#ifdef USE_LIBKVM
+   /* Use BSD-specific kernel memory interface */
+
+   struct kinfo_file *kif;
+   kvm_t *kd;
+   int count;
+   char errstr[_POSIX2_LINE_MAX];
+
+   kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY|KVM_NO_FILES, errstr);
+   assert(kd != NULL);
+   kif = kvm_getfiles(kd, KERN_FILE_BYPID, getpid(), sizeof(struct 
kinfo_file), &count);
+   assert(kif != NULL);
+
+   /* KVM library frees memory on itself */
+   kvm_close(kd);
+   return count;
+#else
+   /* Use /proc filesystem. */
+
DIR *dir;
struct dirent *ent;
int count = 0;
@@ -62,6 +92,7 @@ count_open_fds(void)
closedir(dir);
 
return count;
+#endif
 }
 
 void
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[PATCH 1/8] tests: fix main symbol duplication

2019-02-08 Thread Leonid Bobrov
So far I got these errors before patching:

libtool: link: cc -o .libs/headers-test -pthread -Wall -Wextra 
-Wno-unused-parameter -g -Wstrict-prototypes -Wmissing-prototypes 
-fvisibility=hidden -O2 -pipe tests/headers-test.o 
tests/headers-protocol-test.o tests/headers-protocol-core-test.o 
/tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a -L.libs 
-lwayland-client -lffi -lm -lwayland-server -lkvm -Wl,-rpath-link,/usr/local/lib
ld: error: duplicate symbol: main
>>> defined at headers-test.c:53 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/headers-test.c:53)
>>>tests/headers-test.o:(main)
>>> defined at test-runner.c:377 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/test-runner.c:377)
>>>test-runner.o:(.text+0x250) in archive 
>>> /tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a

libtool: link: cc -o .libs/exec-fd-leak-checker -pthread -Wall -Wextra 
-Wno-unused-parameter -g -Wstrict-prototypes -Wmissing-prototypes 
-fvisibility=hidden -O2 -pipe tests/exec-fd-leak-checker.o 
/tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a -L.libs 
-lwayland-client -lffi -lm -lwayland-server -lkvm -Wl,-rpath-link,/usr/local/lib
ld: error: duplicate symbol: main
>>> defined at exec-fd-leak-checker.c:57 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/exec-fd-leak-checker.c:57)
>>>tests/exec-fd-leak-checker.o:(main)
>>> defined at test-runner.c:377 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/test-runner.c:377)
>>>test-runner.o:(.text+0x250) in archive 
>>> /tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a

Makefile.am: error: object 'tests/test-helpers.$(OBJEXT)' created both with 
libtool and without

libtool: link: cc -o .libs/fixed-benchmark -pthread -Wall -Wextra 
-Wno-unused-parameter -g -Wstrict-prototypes -Wmissing-prototypes 
-fvisibility=hidden -O2 -pipe tests/fixed-benchmark.o 
/tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a -L.libs 
-lwayland-client -lffi -lm -lwayland-server -lkvm -Wl,-rpath-link,/usr/local/lib
ld: error: duplicate symbol: main
>>> defined at fixed-benchmark.c:100 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/fixed-benchmark.c:100)
>>>tests/fixed-benchmark.o:(main)
>>> defined at test-runner.c:377 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/test-runner.c:377)
>>>test-runner.o:(.text+0x250) in archive 
>>> /tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a

This commit fixes all of that.

Signed-off-by: Leonid Bobrov 
---
 Makefile.am | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 697c517..cce4d73 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -210,12 +210,16 @@ noinst_PROGRAMS = \
exec-fd-leak-checker\
fixed-benchmark
 
-noinst_LTLIBRARIES += libtest-runner.la
+noinst_LTLIBRARIES +=  \
+   libtest-runner.la   \
+   libtest-helpers.la
+
+libtest_helpers_la_SOURCES = tests/test-helpers.c
+libtest_helpers_la_LIBADD = -lrt -ldl $(FFI_LIBS)
 
 libtest_runner_la_SOURCES =\
tests/test-runner.c \
tests/test-runner.h \
-   tests/test-helpers.c\
tests/test-compositor.h \
tests/test-compositor.c
 libtest_runner_la_LIBADD = \
@@ -223,8 +227,7 @@ libtest_runner_la_LIBADD =  \
libwayland-util.la  \
libwayland-client.la\
libwayland-server.la\
-   -lrt -ldl $(FFI_LIBS)
-
+   libtest-helpers.la
 
 array_test_SOURCES = tests/array-test.c
 array_test_LDADD = libtest-runner.la
@@ -270,7 +273,6 @@ protocol_logger_test_LDADD = libtest-runner.la
 headers_test_SOURCES = tests/headers-test.c \
   tests/headers-protocol-test.c \
   tests/headers-protocol-core-test.c
-headers_test_LDADD = libtest-runner.la
 nodist_headers_test_SOURCES =  \
protocol/wayland-server-protocol-core.h \
protocol/wayland-client-protocol-core.h
@@ -280,13 +282,12 @@ cpp_compile_test_SOURCES = tests/cpp-compile-test.cpp
 endif
 
 fixed_benchmark_SOURCES = tests/fixed-benchmark.c
-fixed_benchmark_LDADD = libtest-runner.la
 
 os_wrappers_test_SOURCES = tests/os-wrappers-test.c
 os_wrappers_test_LDADD = libtest-runner.la
 
 exec_fd_leak_checker_SOURCES = tests/exec-fd-leak-checker.c
-exec_fd_leak_checker_LDADD = libtest-runner.la
+exec_fd_leak_checker_LDADD = libtest-helpers.la
 
 EXTRA_DIST += tests/scanner-test.sh\
protocol/tests.xml  \
-- 
2.20.1

___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


Support OpenBSD

2019-02-08 Thread Leonid Bobrov
From 6b2cd23b0681a7ad253201071d243cbefc1bc0aa Mon Sep 17 00:00:00 2001
From: Leonid Bobrov 
Date: Thu, 7 Feb 2019 18:02:57 +0200
Subject: [PATCH 1/8] tests: fix main symbol duplication

So far I got these errors before patching:

libtool: link: cc -o .libs/headers-test -pthread -Wall -Wextra 
-Wno-unused-parameter -g -Wstrict-prototypes -Wmissing-prototypes 
-fvisibility=hidden -O2 -pipe tests/headers-test.o 
tests/headers-protocol-test.o tests/headers-protocol-core-test.o 
/tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a -L.libs 
-lwayland-client -lffi -lm -lwayland-server -lkvm -Wl,-rpath-link,/usr/local/lib
ld: error: duplicate symbol: main
>>> defined at headers-test.c:53 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/headers-test.c:53)
>>>tests/headers-test.o:(main)
>>> defined at test-runner.c:377 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/test-runner.c:377)
>>>test-runner.o:(.text+0x250) in archive 
>>> /tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a

libtool: link: cc -o .libs/exec-fd-leak-checker -pthread -Wall -Wextra 
-Wno-unused-parameter -g -Wstrict-prototypes -Wmissing-prototypes 
-fvisibility=hidden -O2 -pipe tests/exec-fd-leak-checker.o 
/tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a -L.libs 
-lwayland-client -lffi -lm -lwayland-server -lkvm -Wl,-rpath-link,/usr/local/lib
ld: error: duplicate symbol: main
>>> defined at exec-fd-leak-checker.c:57 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/exec-fd-leak-checker.c:57)
>>>tests/exec-fd-leak-checker.o:(main)
>>> defined at test-runner.c:377 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/test-runner.c:377)
>>>test-runner.o:(.text+0x250) in archive 
>>> /tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a

Makefile.am: error: object 'tests/test-helpers.$(OBJEXT)' created both with 
libtool and without

libtool: link: cc -o .libs/fixed-benchmark -pthread -Wall -Wextra 
-Wno-unused-parameter -g -Wstrict-prototypes -Wmissing-prototypes 
-fvisibility=hidden -O2 -pipe tests/fixed-benchmark.o 
/tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a -L.libs 
-lwayland-client -lffi -lm -lwayland-server -lkvm -Wl,-rpath-link,/usr/local/lib
ld: error: duplicate symbol: main
>>> defined at fixed-benchmark.c:100 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/fixed-benchmark.c:100)
>>>tests/fixed-benchmark.o:(main)
>>> defined at test-runner.c:377 
>>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/test-runner.c:377)
>>>test-runner.o:(.text+0x250) in archive 
>>> /tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a

This commit fixes all of that.

Signed-off-by: Leonid Bobrov 
---
 Makefile.am | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 697c517..cce4d73 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -210,12 +210,16 @@ noinst_PROGRAMS = \
exec-fd-leak-checker\
fixed-benchmark
 
-noinst_LTLIBRARIES += libtest-runner.la
+noinst_LTLIBRARIES +=  \
+   libtest-runner.la   \
+   libtest-helpers.la
+
+libtest_helpers_la_SOURCES = tests/test-helpers.c
+libtest_helpers_la_LIBADD = -lrt -ldl $(FFI_LIBS)
 
 libtest_runner_la_SOURCES =\
tests/test-runner.c \
tests/test-runner.h \
-   tests/test-helpers.c\
tests/test-compositor.h \
tests/test-compositor.c
 libtest_runner_la_LIBADD = \
@@ -223,8 +227,7 @@ libtest_runner_la_LIBADD =  \
libwayland-util.la  \
libwayland-client.la\
libwayland-server.la\
-   -lrt -ldl $(FFI_LIBS)
-
+   libtest-helpers.la
 
 array_test_SOURCES = tests/array-test.c
 array_test_LDADD = libtest-runner.la
@@ -270,7 +273,6 @@ protocol_logger_test_LDADD = libtest-runner.la
 headers_test_SOURCES = tests/headers-test.c \
   tests/headers-protocol-test.c \
   tests/headers-protocol-core-test.c
-headers_test_LDADD = libtest-runner.la
 nodist_headers_test_SOURCES =  \
protocol/wayland-server-protocol-core.h \
protocol/wayland-client-protocol-core.h
@@ -280,13 +282,12 @@ cpp_compile_test_SOURCES = tests/cpp-compile-test.cpp
 endif
 
 fixed_benchmark_SOURCES = tests/fixed-benchmark.c
-fixed_benchmark_LDADD = libtest-runner.la
 
 os_wrappers_test_SOURCES = tests/os-wrappers-test.c
 os_wrappers_test_LDADD = libtest-runner.la
 
 exec_fd_leak_checker_SOURCES = tests/exec-fd-leak-checker.c
-exec_fd_leak_checker_LDADD = libtest-runner.la
+exec_fd_leak_checker_LDADD = libtest-helpers.la
 
 EXTRA_DIST += tests/scanner-test.sh\
protocol/tests.xml  \
-- 
2.20.1


Fro

Re: tests: fix main symbol duplication

2019-02-08 Thread Leonid Bobrov
On Fri, Feb 08, 2019 at 12:51:23PM +0200, Pekka Paalanen wrote:
> Weird indeed. Did you manually edit the patch, or copy & paste it?
> 

Copied & pasted it, next time I'll include them in MIME

> > I don't know how to do that, besides I have no intention to license code
> > I submit, so you are completely free to use it.
> 
> The way you do that is you put
> 
> Signed-off-by: Your Real Name 
> 
> at the end of each commit message. You can check almost any existing
> Wayland commit for an example.
> 

Ok.

> If you do not license your code under the very license the project is
> using, then we cannot take your contributions at all. No license means
> no-one can do anything with it, particularly redistribute it. I once saw
> someone say: the copyright law makes no difference between your patch
> and the latest Disney movie.
> 
> No license: no rights.
> 
> "Feel free to use it" is not a license. We really do need a valid
> license for all contributions. The way that happens is that people
> check the project license (in this case it is duplicated in the top of
> almost every source file, and in the COPYING file at the root
> directory) and agree to that. Putting your S-o-b in the commit message
> is an explicit indicator that you agree, but also the fact that you
> sent a patch at all can also be taken as an agreement.
> 
> 
> Thanks,
> pq
> 

Ok, got it.
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


[ANNOUNCE] libxkbcommon 0.8.3

2019-02-08 Thread Ran Benita
Build note: We've had a report that the autotools build doesn't work with
the new version of Bison, 3.3. If this happens to you, please switch to
using meson. The autotools build will be removed in libxkbcommon 0.9.0.

libxkbcommon 0.8.3
==

- Fix build of static libraries with meson.

- New API:
  XKB_KEY_XF86MonBrightnessCycle
  XKB_KEY_XF86RotationLockToggle

Tarball:


git tag: xkbcommon-0.8.3

https://xkbcommon.org/download/libxkbcommon-0.8.3.tar.xz
MD5:8225a206e00c4146d2e06f5e688b28e7  libxkbcommon-0.8.3.tar.xz
SHA1:   98efddc6b1d306f61b7786861730ad65a178f71a  libxkbcommon-0.8.3.tar.xz
SHA256: b855c629849a97ab9835a4ad99d6b749a636f70d38a03f070c6ef72024825540  
libxkbcommon-0.8.3.tar.xz

Ran
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: tests: fix main symbol duplication

2019-02-08 Thread Pekka Paalanen
On Fri, 8 Feb 2019 12:23:06 +0200
Leonid Bobrov  wrote:

> On Fri, Feb 08, 2019 at 12:09:09PM +0200, Pekka Paalanen wrote:
> > Hi Leonid,
> >   
> 
> Hi Pekka,
> 
> > your approach to fix these issues looks good to me, and the commit
> > message explains everything I could ask for, except for maybe
> > mentioning that the linker is one from OpenBSD, was it?
> > 
> > Unfortunately it seems the patch is somehow malformed:
> > 
> > git am -3 
> > /home/pq/.claws-mail/imapcache/imap.gmail.com/ppaala...@gmail.com/lists/wayland-devel/39311
> > ---
> > Applying: tests: fix main symbol duplication
> > error: git diff header lacks filename information when removing 1 leading 
> > pathname component (line 9)
> > error: could not build fake ancestor
> > Patch failed at 0001 tests: fix main symbol duplication
> > 
> > It does not look like it came from git-format-patch.
> >   
> 
> Weird, because I ran $ git format-patch HEAD~1

Weird indeed. Did you manually edit the patch, or copy & paste it?

The diff line file names are missing the typical a/ and b/ like this:

diff --git a/libweston-desktop/internal.h b/libweston-desktop/internal.h
index 2f2af98c..ce853ba9 100644
--- a/libweston-desktop/internal.h
+++ b/libweston-desktop/internal.h

> > Could you retry, please?
> > 
> > I guess that you might be sending more patches, therefore it would be
> > nice to get the workflow in order so I don't have to manually redo
> > every patch.
> >   
> 
> Yes, I am preparing more patches, trying to divide src/event-loop.c
> into src/event-loop-epoll.c and srs/event-loop-kqueue.c
> 
> > Would you consider adding a Signed-off-by as well to show that you
> > agree to https://developercertificate.org/ too?
> >   
> 
> I don't know how to do that, besides I have no intention to license code
> I submit, so you are completely free to use it.

The way you do that is you put

Signed-off-by: Your Real Name 

at the end of each commit message. You can check almost any existing
Wayland commit for an example.

If you do not license your code under the very license the project is
using, then we cannot take your contributions at all. No license means
no-one can do anything with it, particularly redistribute it. I once saw
someone say: the copyright law makes no difference between your patch
and the latest Disney movie.

No license: no rights.

"Feel free to use it" is not a license. We really do need a valid
license for all contributions. The way that happens is that people
check the project license (in this case it is duplicated in the top of
almost every source file, and in the COPYING file at the root
directory) and agree to that. Putting your S-o-b in the commit message
is an explicit indicator that you agree, but also the fact that you
sent a patch at all can also be taken as an agreement.


Thanks,
pq

> 
> > S-o-b is mentioned in
> > https://gitlab.freedesktop.org/wayland/wayland/blob/master/CONTRIBUTING.md#sending-patches
> >  .
> > 
> > 
> > Thanks,
> > pq
> >   



pgpqchfQsZEQW.pgp
Description: OpenPGP digital signature
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: tests: fix main symbol duplication

2019-02-08 Thread Leonid Bobrov
On Fri, Feb 08, 2019 at 12:09:09PM +0200, Pekka Paalanen wrote:
> Hi Leonid,
> 

Hi Pekka,

> your approach to fix these issues looks good to me, and the commit
> message explains everything I could ask for, except for maybe
> mentioning that the linker is one from OpenBSD, was it?
> 
> Unfortunately it seems the patch is somehow malformed:
> 
> git am -3 
> /home/pq/.claws-mail/imapcache/imap.gmail.com/ppaala...@gmail.com/lists/wayland-devel/39311
> ---
> Applying: tests: fix main symbol duplication
> error: git diff header lacks filename information when removing 1 leading 
> pathname component (line 9)
> error: could not build fake ancestor
> Patch failed at 0001 tests: fix main symbol duplication
> 
> It does not look like it came from git-format-patch.
> 

Weird, because I ran $ git format-patch HEAD~1

> Could you retry, please?
> 
> I guess that you might be sending more patches, therefore it would be
> nice to get the workflow in order so I don't have to manually redo
> every patch.
> 

Yes, I am preparing more patches, trying to divide src/event-loop.c
into src/event-loop-epoll.c and srs/event-loop-kqueue.c

> Would you consider adding a Signed-off-by as well to show that you
> agree to https://developercertificate.org/ too?
> 

I don't know how to do that, besides I have no intention to license code
I submit, so you are completely free to use it.

> S-o-b is mentioned in
> https://gitlab.freedesktop.org/wayland/wayland/blob/master/CONTRIBUTING.md#sending-patches
>  .
> 
> 
> Thanks,
> pq
> 
___
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel


Re: tests: fix main symbol duplication

2019-02-08 Thread Pekka Paalanen
On Thu, 7 Feb 2019 18:07:36 +0200
Leonid Bobrov  wrote:

> From b00351a95d98e4ecc8efe9c7f1e5c56e79fe5f9f Mon Sep 17 00:00:00 2001
> From: Leonid Bobrov 
> Date: Thu, 7 Feb 2019 18:02:57 +0200
> Subject: [PATCH] tests: fix main symbol duplication

Hi Leonid,

your approach to fix these issues looks good to me, and the commit
message explains everything I could ask for, except for maybe
mentioning that the linker is one from OpenBSD, was it?

Unfortunately it seems the patch is somehow malformed:

git am -3 
/home/pq/.claws-mail/imapcache/imap.gmail.com/ppaala...@gmail.com/lists/wayland-devel/39311
---
Applying: tests: fix main symbol duplication
error: git diff header lacks filename information when removing 1 leading 
pathname component (line 9)
error: could not build fake ancestor
Patch failed at 0001 tests: fix main symbol duplication

It does not look like it came from git-format-patch.

Could you retry, please?

I guess that you might be sending more patches, therefore it would be
nice to get the workflow in order so I don't have to manually redo
every patch.

Would you consider adding a Signed-off-by as well to show that you
agree to https://developercertificate.org/ too?

S-o-b is mentioned in
https://gitlab.freedesktop.org/wayland/wayland/blob/master/CONTRIBUTING.md#sending-patches
 .


Thanks,
pq

> 
> So far I got these errors before patching:
> 
> libtool: link: cc -o .libs/headers-test -pthread -Wall -Wextra 
> -Wno-unused-parameter -g -Wstrict-prototypes -Wmissing-prototypes 
> -fvisibility=hidden -O2 -pipe tests/headers-test.o 
> tests/headers-protocol-test.o tests/headers-protocol-core-test.o 
> /tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a -L.libs 
> -lwayland-client -lffi -lm -lwayland-server -lkvm 
> -Wl,-rpath-link,/usr/local/lib
> ld: error: duplicate symbol: main
> >>> defined at headers-test.c:53 
> >>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/headers-test.c:53)
> >>>tests/headers-test.o:(main)
> >>> defined at test-runner.c:377 
> >>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/test-runner.c:377)
> >>>test-runner.o:(.text+0x250) in archive 
> >>> /tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a  
> 
> libtool: link: cc -o .libs/exec-fd-leak-checker -pthread -Wall -Wextra 
> -Wno-unused-parameter -g -Wstrict-prototypes -Wmissing-prototypes 
> -fvisibility=hidden -O2 -pipe tests/exec-fd-leak-checker.o 
> /tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a -L.libs 
> -lwayland-client -lffi -lm -lwayland-server -lkvm 
> -Wl,-rpath-link,/usr/local/lib
> ld: error: duplicate symbol: main
> >>> defined at exec-fd-leak-checker.c:57 
> >>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/exec-fd-leak-checker.c:57)
> >>>tests/exec-fd-leak-checker.o:(main)
> >>> defined at test-runner.c:377 
> >>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/test-runner.c:377)
> >>>test-runner.o:(.text+0x250) in archive 
> >>> /tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a  
> 
> Makefile.am: error: object 'tests/test-helpers.$(OBJEXT)' created both with 
> libtool and without
> 
> libtool: link: cc -o .libs/fixed-benchmark -pthread -Wall -Wextra 
> -Wno-unused-parameter -g -Wstrict-prototypes -Wmissing-prototypes 
> -fvisibility=hidden -O2 -pipe tests/fixed-benchmark.o 
> /tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a -L.libs 
> -lwayland-client -lffi -lm -lwayland-server -lkvm 
> -Wl,-rpath-link,/usr/local/lib
> ld: error: duplicate symbol: main
> >>> defined at fixed-benchmark.c:100 
> >>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/fixed-benchmark.c:100)
> >>>tests/fixed-benchmark.o:(main)
> >>> defined at test-runner.c:377 
> >>> (/tmp/obj/wayland-1.16.0/wayland-1.16.0/tests/test-runner.c:377)
> >>>test-runner.o:(.text+0x250) in archive 
> >>> /tmp/obj/wayland-1.16.0/build-amd64/.libs/libtest-runner.a  
> 
> This commit fixes all of that.
> ---
>  Makefile.am | 15 ---
>  1 file changed, 8 insertions(+), 7 deletions(-)
> 
> diff --git Makefile.am Makefile.am
> index 697c517..cce4d73 100644
> --- Makefile.am
> +++ Makefile.am
> @@ -210,12 +210,16 @@ noinst_PROGRAMS =   \
>   exec-fd-leak-checker\
>   fixed-benchmark
>  
> -noinst_LTLIBRARIES += libtest-runner.la
> +noinst_LTLIBRARIES +=\
> + libtest-runner.la   \
> + libtest-helpers.la
> +
> +libtest_helpers_la_SOURCES = tests/test-helpers.c
> +libtest_helpers_la_LIBADD = -lrt -ldl $(FFI_LIBS)
>  
>  libtest_runner_la_SOURCES =  \
>   tests/test-runner.c \
>   tests/test-runner.h \
> - tests/test-helpers.c\
>   tests/test-compositor.h \
>   tests/test-compositor.c
>  libtest_runner_la_LIBADD =   \
> @@ -223,8 +