Re: [PATCH v8 2/6] tests: support waitpid
You know, I think this whole patch is silly, because waitid() is part of POSIX, FreeBSD and NetBSD implement it while OpenBSD and DragonFly BSD don't. I'll ask OpenBSD upstream to merge NetBSD's implementation and DragonFly BSD upstream to merge FreeBSD's implementation. OpenBSD aims standardization so we should blame OpenBSD. ___ wayland-devel mailing list wayland-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/wayland-devel
[PATCH v8 5/6] tests: add OS-specific tracing to runner
From: Vadim Zhukov Co-authored-by: Koop Mast 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 c5ead62..a60a927 100644 --- a/configure.ac +++ b/configure.ac @@ -69,6 +69,9 @@ AC_CHECK_FUNCS([accept4 mkostemp posix_fallocate prctl]) AC_CHECK_FUNCS([mremap]) AC_CHECK_HEADERS([sys/mman.h]) +# 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 v8 1/6] tests: use /dev/fd to count open fds
*BSD don't have /proc/self/fd, they use /dev/fd instead. At Linux /dev/fd is a symlink to /proc/self/fd Signed-off-by: Leonid Bobrov --- tests/test-helpers.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test-helpers.c b/tests/test-helpers.c index b2189d8..03419fb 100644 --- a/tests/test-helpers.c +++ b/tests/test-helpers.c @@ -47,8 +47,8 @@ count_open_fds(void) struct dirent *ent; int count = 0; - dir = opendir("/proc/self/fd"); - assert(dir && "opening /proc/self/fd failed."); + dir = opendir("/dev/fd"); + assert(dir && "opening /dev/fd failed."); errno = 0; while ((ent = readdir(dir))) { @@ -57,7 +57,7 @@ count_open_fds(void) continue; count++; } - assert(errno == 0 && "reading /proc/self/fd failed."); + assert(errno == 0 && "reading /dev/fd failed."); closedir(dir); -- 2.20.1 ___ wayland-devel mailing list wayland-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/wayland-devel
[PATCH v8 3/6] shm: use workaround if mremap is not available
From: Imre Vadász 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 c0f1c37..dcefc78 100644 --- a/configure.ac +++ b/configure.ac @@ -65,6 +65,10 @@ AC_SUBST(GCC_CFLAGS) AC_CHECK_HEADERS([sys/prctl.h]) AC_CHECK_FUNCS([accept4 mkostemp posix_fallocate prctl]) +# 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 4191231..5bfdece 100644 --- a/src/wayland-shm.c +++ b/src/wayland-shm.c @@ -40,6 +40,9 @@ #include #include #include +#ifdef HAVE_SYS_PARAM_H +#include +#endif #include "wayland-util.h" #include "wayland-private.h" @@ -84,7 +87,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, @@ -495,6 +515,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, @@ -502,6 +523,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 v8 4/6] server: add *BSD credentials support
From: Vadim Zhukov Co-authored-by: Koop Mast 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 dcefc78..c5ead62 100644 --- a/configure.ac +++ b/configure.ac @@ -73,6 +73,9 @@ AC_CHECK_HEADERS([sys/mman.h]) AC_CHECK_FUNCS([waitid]) AC_CHECK_HEADERS([signal.h]) +# Credential support on *BSD +AC_CHECK_HEADERS([sys/ucred.h]) + AC_ARG_ENABLE([libraries], [AC_HELP_STRING([--disable-libraries], [Disable compilation of wayland libraries])], 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 5bfdece..567dedf 100644 --- a/src/wayland-shm.c +++ b/src/wayland-shm.c @@ -28,6 +28,8 @@ * */ +#include "config.h" + #define _GNU_SOURCE #include @@ -62,6 +64,7 @@ struct wl_shm_pool { char *data; int32_t size; int32_t new_size; + int fd; }; struct wl_shm_buffer { @@ -130,6 +133,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); } @@ -304,7 +310,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 v8 6/6] configure: detect libdl and librt
Signed-off-by: Leonid Bobrov --- Makefile.am | 6 +++--- configure.ac | 6 ++ m4/weston.m4 | 37 + 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 m4/weston.m4 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 a60a927..064b8a8 100644 --- a/configure.ac +++ b/configure.ac @@ -79,6 +79,12 @@ AC_CHECK_HEADERS([signal.h]) # Credential support on *BSD AC_CHECK_HEADERS([sys/ucred.h]) +# *BSD don't have libdl, but they have its functions in libc +WESTON_SEARCH_LIBS([DL], [dl], [dlsym]) + +# OpenBSD doesn't have librt, but it has its functions in libc +WESTON_SEARCH_LIBS([RT], [rt], [clock_gettime]) + AC_ARG_ENABLE([libraries], [AC_HELP_STRING([--disable-libraries], [Disable compilation of wayland libraries])], diff --git a/m4/weston.m4 b/m4/weston.m4 new file mode 100644 index 000..636f9fb --- /dev/null +++ b/m4/weston.m4 @@ -0,0 +1,37 @@ +dnl +dnl Copyright © 2016 Quentin “Sardem FF7” Glidic +dnl +dnl Permission is hereby granted, free of charge, to any person obtaining a +dnl copy of this software and associated documentation files (the "Software"), +dnl to deal in the Software without restriction, including without limitation +dnl the rights to use, copy, modify, merge, publish, distribute, sublicense, +dnl and/or sell copies of the Software, and to permit persons to whom the +dnl Software is furnished to do so, subject to the following conditions: +dnl +dnl The above copyright notice and this permission notice (including the next +dnl paragraph) shall be included in all copies or substantial portions of the +dnl Software. +dnl +dnl THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +dnl IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +dnl FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +dnl THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +dnl LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +dnl FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +dnl DEALINGS IN THE SOFTWARE. +dnl + +dnl WESTON_SEARCH_LIBS(PREFIX, search-libs, function, [action-if-found], [action-if-not-found], [other-libraries]) +dnl WESTON_SEARCH_LIBS is a wrapper around AC_SEARCH_LIBS with a little difference: +dnl action-if-found is called even if no library is required +AC_DEFUN([WESTON_SEARCH_LIBS], [ + weston_save_LIBS=${LIBS} + AC_SEARCH_LIBS([$3], [$2], [$4], [$5], [$6]) + AS_CASE([${ac_cv_search_][$3][}], + ['none required'], [$4], + [no], [], + [$1][_LIBS=${ac_cv_search_][$3][}] + ) + AC_SUBST([$1][_LIBS]) + LIBS=${weston_save_LIBS} +]) -- 2.20.1 ___ wayland-devel mailing list wayland-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/wayland-devel
[PATCH v8 2/6] tests: support waitpid
From: Vadim Zhukov *BSD don't have waitid() Co-authored-by: Koop Mast 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 495e1a6..c0f1c37 100644 --- a/configure.ac +++ b/configure.ac @@ -65,6 +65,10 @@ AC_SUBST(GCC_CFLAGS) AC_CHECK_HEADERS([sys/prctl.h]) AC_CHECK_FUNCS([accept4 mkostemp posix_fallocate prctl]) +# 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 v7 6/6] configure: detect libdl and librt
Signed-off-by: Leonid Bobrov --- Makefile.am | 6 +++--- configure.ac | 6 ++ m4/weston.m4 | 37 + 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 m4/weston.m4 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 a60a927..064b8a8 100644 --- a/configure.ac +++ b/configure.ac @@ -79,6 +79,12 @@ AC_CHECK_HEADERS([signal.h]) # Credential support on *BSD AC_CHECK_HEADERS([sys/ucred.h]) +# *BSD don't have libdl, but they have its functions in libc +WESTON_SEARCH_LIBS([DL], [dl], [dlsym]) + +# OpenBSD doesn't have librt, but it has its functions in libc +WESTON_SEARCH_LIBS([RT], [rt], [clock_gettime]) + AC_ARG_ENABLE([libraries], [AC_HELP_STRING([--disable-libraries], [Disable compilation of wayland libraries])], diff --git a/m4/weston.m4 b/m4/weston.m4 new file mode 100644 index 000..636f9fb --- /dev/null +++ b/m4/weston.m4 @@ -0,0 +1,37 @@ +dnl +dnl Copyright © 2016 Quentin “Sardem FF7” Glidic +dnl +dnl Permission is hereby granted, free of charge, to any person obtaining a +dnl copy of this software and associated documentation files (the "Software"), +dnl to deal in the Software without restriction, including without limitation +dnl the rights to use, copy, modify, merge, publish, distribute, sublicense, +dnl and/or sell copies of the Software, and to permit persons to whom the +dnl Software is furnished to do so, subject to the following conditions: +dnl +dnl The above copyright notice and this permission notice (including the next +dnl paragraph) shall be included in all copies or substantial portions of the +dnl Software. +dnl +dnl THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +dnl IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +dnl FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +dnl THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +dnl LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +dnl FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +dnl DEALINGS IN THE SOFTWARE. +dnl + +dnl WESTON_SEARCH_LIBS(PREFIX, search-libs, function, [action-if-found], [action-if-not-found], [other-libraries]) +dnl WESTON_SEARCH_LIBS is a wrapper around AC_SEARCH_LIBS with a little difference: +dnl action-if-found is called even if no library is required +AC_DEFUN([WESTON_SEARCH_LIBS], [ + weston_save_LIBS=${LIBS} + AC_SEARCH_LIBS([$3], [$2], [$4], [$5], [$6]) + AS_CASE([${ac_cv_search_][$3][}], + ['none required'], [$4], + [no], [], + [$1][_LIBS=${ac_cv_search_][$3][}] + ) + AC_SUBST([$1][_LIBS]) + LIBS=${weston_save_LIBS} +]) -- 2.20.1 ___ wayland-devel mailing list wayland-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/wayland-devel
[PATCH v7 2/6] tests: support waitpid
From: Vadim Zhukov *BSD don't have waitid() Co-authored-by: Koop Mast Signed-off-by: Vadim Zhukov Signed-off-by: Koop Mast 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 495e1a6..c0f1c37 100644 --- a/configure.ac +++ b/configure.ac @@ -65,6 +65,10 @@ AC_SUBST(GCC_CFLAGS) AC_CHECK_HEADERS([sys/prctl.h]) AC_CHECK_FUNCS([accept4 mkostemp posix_fallocate prctl]) +# 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 v7 3/6] shm: use workaround if mremap is not available
From: Imre Vadász Signed-off-by: Imre Vadász 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 c0f1c37..dcefc78 100644 --- a/configure.ac +++ b/configure.ac @@ -65,6 +65,10 @@ AC_SUBST(GCC_CFLAGS) AC_CHECK_HEADERS([sys/prctl.h]) AC_CHECK_FUNCS([accept4 mkostemp posix_fallocate prctl]) +# 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 4191231..5bfdece 100644 --- a/src/wayland-shm.c +++ b/src/wayland-shm.c @@ -40,6 +40,9 @@ #include #include #include +#ifdef HAVE_SYS_PARAM_H +#include +#endif #include "wayland-util.h" #include "wayland-private.h" @@ -84,7 +87,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, @@ -495,6 +515,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, @@ -502,6 +523,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 v7 4/6] server: add *BSD credentials support
From: Vadim Zhukov Co-authored-by: Koop Mast Signed-off-by: Vadim Zhukov Signed-off-by: Koop Mast 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 dcefc78..c5ead62 100644 --- a/configure.ac +++ b/configure.ac @@ -73,6 +73,9 @@ AC_CHECK_HEADERS([sys/mman.h]) AC_CHECK_FUNCS([waitid]) AC_CHECK_HEADERS([signal.h]) +# Credential support on *BSD +AC_CHECK_HEADERS([sys/ucred.h]) + AC_ARG_ENABLE([libraries], [AC_HELP_STRING([--disable-libraries], [Disable compilation of wayland libraries])], 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 5bfdece..567dedf 100644 --- a/src/wayland-shm.c +++ b/src/wayland-shm.c @@ -28,6 +28,8 @@ * */ +#include "config.h" + #define _GNU_SOURCE #include @@ -62,6 +64,7 @@ struct wl_shm_pool { char *data; int32_t size; int32_t new_size; + int fd; }; struct wl_shm_buffer { @@ -130,6 +133,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); } @@ -304,7 +310,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 v7 5/6] tests: add OS-specific tracing to runner
From: Vadim Zhukov Co-authored-by: Koop Mast Signed-off-by: Vadim Zhukov Signed-off-by: Koop Mast 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 c5ead62..a60a927 100644 --- a/configure.ac +++ b/configure.ac @@ -69,6 +69,9 @@ AC_CHECK_FUNCS([accept4 mkostemp posix_fallocate prctl]) AC_CHECK_FUNCS([mremap]) AC_CHECK_HEADERS([sys/mman.h]) +# 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 v7 1/6] tests: use /dev/fd to count open fds
From: Johannes Lundberg *BSD don't have /proc/self/fd, they use /dev/fd instead. At Linux /dev/fd is a symlink to /proc/self/fd Signed-off-by: Johannes Lundberg Signed-off-by: Leonid Bobrov --- tests/test-helpers.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test-helpers.c b/tests/test-helpers.c index b2189d8..03419fb 100644 --- a/tests/test-helpers.c +++ b/tests/test-helpers.c @@ -47,8 +47,8 @@ count_open_fds(void) struct dirent *ent; int count = 0; - dir = opendir("/proc/self/fd"); - assert(dir && "opening /proc/self/fd failed."); + dir = opendir("/dev/fd"); + assert(dir && "opening /dev/fd failed."); errno = 0; while ((ent = readdir(dir))) { @@ -57,7 +57,7 @@ count_open_fds(void) continue; count++; } - assert(errno == 0 && "reading /proc/self/fd failed."); + assert(errno == 0 && "reading /dev/fd failed."); closedir(dir); -- 2.20.1 ___ wayland-devel mailing list wayland-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/wayland-devel
[PATCH v6 3/6] shm: use workaround if mremap is not available
From: Imre Vadász 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 c0f1c37..dcefc78 100644 --- a/configure.ac +++ b/configure.ac @@ -65,6 +65,10 @@ AC_SUBST(GCC_CFLAGS) AC_CHECK_HEADERS([sys/prctl.h]) AC_CHECK_FUNCS([accept4 mkostemp posix_fallocate prctl]) +# 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 4191231..5bfdece 100644 --- a/src/wayland-shm.c +++ b/src/wayland-shm.c @@ -40,6 +40,9 @@ #include #include #include +#ifdef HAVE_SYS_PARAM_H +#include +#endif #include "wayland-util.h" #include "wayland-private.h" @@ -84,7 +87,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, @@ -495,6 +515,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, @@ -502,6 +523,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 v6 2/6] tests: support waitpid
From: Vadim Zhukov *BSD don't have waitid() Co-authored-by: Koop Mast 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 495e1a6..c0f1c37 100644 --- a/configure.ac +++ b/configure.ac @@ -65,6 +65,10 @@ AC_SUBST(GCC_CFLAGS) AC_CHECK_HEADERS([sys/prctl.h]) AC_CHECK_FUNCS([accept4 mkostemp posix_fallocate prctl]) +# 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 v6 4/6] server: add *BSD credentials support
From: Vadim Zhukov Co-authored-by: Koop Mast 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 dcefc78..c5ead62 100644 --- a/configure.ac +++ b/configure.ac @@ -73,6 +73,9 @@ AC_CHECK_HEADERS([sys/mman.h]) AC_CHECK_FUNCS([waitid]) AC_CHECK_HEADERS([signal.h]) +# Credential support on *BSD +AC_CHECK_HEADERS([sys/ucred.h]) + AC_ARG_ENABLE([libraries], [AC_HELP_STRING([--disable-libraries], [Disable compilation of wayland libraries])], 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 5bfdece..567dedf 100644 --- a/src/wayland-shm.c +++ b/src/wayland-shm.c @@ -28,6 +28,8 @@ * */ +#include "config.h" + #define _GNU_SOURCE #include @@ -62,6 +64,7 @@ struct wl_shm_pool { char *data; int32_t size; int32_t new_size; + int fd; }; struct wl_shm_buffer { @@ -130,6 +133,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); } @@ -304,7 +310,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 v6 5/6] tests: add OS-specific tracing to runner
From: Vadim Zhukov Co-authored-by: Koop Mast 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 c5ead62..a60a927 100644 --- a/configure.ac +++ b/configure.ac @@ -69,6 +69,9 @@ AC_CHECK_FUNCS([accept4 mkostemp posix_fallocate prctl]) AC_CHECK_FUNCS([mremap]) AC_CHECK_HEADERS([sys/mman.h]) +# 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 v6 1/6] tests: use /dev/fd to count open fds
From: Johannes Lundberg *BSD don't have /proc/self/fd, they use /dev/fd instead. At Linux /dev/fd is a symlink to /proc/self/fd Signed-off-by: Leonid Bobrov --- tests/test-helpers.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test-helpers.c b/tests/test-helpers.c index b2189d8..03419fb 100644 --- a/tests/test-helpers.c +++ b/tests/test-helpers.c @@ -47,8 +47,8 @@ count_open_fds(void) struct dirent *ent; int count = 0; - dir = opendir("/proc/self/fd"); - assert(dir && "opening /proc/self/fd failed."); + dir = opendir("/dev/fd"); + assert(dir && "opening /dev/fd failed."); errno = 0; while ((ent = readdir(dir))) { @@ -57,7 +57,7 @@ count_open_fds(void) continue; count++; } - assert(errno == 0 && "reading /proc/self/fd failed."); + assert(errno == 0 && "reading /dev/fd failed."); closedir(dir); -- 2.20.1 ___ wayland-devel mailing list wayland-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/wayland-devel
[PATCH v6 6/6] configure: detect libdl and librt
Signed-off-by: Leonid Bobrov --- Makefile.am | 6 +++--- configure.ac | 6 ++ m4/weston.m4 | 37 + 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 m4/weston.m4 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 a60a927..064b8a8 100644 --- a/configure.ac +++ b/configure.ac @@ -79,6 +79,12 @@ AC_CHECK_HEADERS([signal.h]) # Credential support on *BSD AC_CHECK_HEADERS([sys/ucred.h]) +# *BSD don't have libdl, but they have its functions in libc +WESTON_SEARCH_LIBS([DL], [dl], [dlsym]) + +# OpenBSD doesn't have librt, but it has its functions in libc +WESTON_SEARCH_LIBS([RT], [rt], [clock_gettime]) + AC_ARG_ENABLE([libraries], [AC_HELP_STRING([--disable-libraries], [Disable compilation of wayland libraries])], diff --git a/m4/weston.m4 b/m4/weston.m4 new file mode 100644 index 000..636f9fb --- /dev/null +++ b/m4/weston.m4 @@ -0,0 +1,37 @@ +dnl +dnl Copyright © 2016 Quentin “Sardem FF7” Glidic +dnl +dnl Permission is hereby granted, free of charge, to any person obtaining a +dnl copy of this software and associated documentation files (the "Software"), +dnl to deal in the Software without restriction, including without limitation +dnl the rights to use, copy, modify, merge, publish, distribute, sublicense, +dnl and/or sell copies of the Software, and to permit persons to whom the +dnl Software is furnished to do so, subject to the following conditions: +dnl +dnl The above copyright notice and this permission notice (including the next +dnl paragraph) shall be included in all copies or substantial portions of the +dnl Software. +dnl +dnl THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +dnl IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +dnl FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +dnl THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +dnl LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +dnl FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +dnl DEALINGS IN THE SOFTWARE. +dnl + +dnl WESTON_SEARCH_LIBS(PREFIX, search-libs, function, [action-if-found], [action-if-not-found], [other-libraries]) +dnl WESTON_SEARCH_LIBS is a wrapper around AC_SEARCH_LIBS with a little difference: +dnl action-if-found is called even if no library is required +AC_DEFUN([WESTON_SEARCH_LIBS], [ + weston_save_LIBS=${LIBS} + AC_SEARCH_LIBS([$3], [$2], [$4], [$5], [$6]) + AS_CASE([${ac_cv_search_][$3][}], + ['none required'], [$4], + [no], [], + [$1][_LIBS=${ac_cv_search_][$3][}] + ) + AC_SUBST([$1][_LIBS]) + LIBS=${weston_save_LIBS} +]) -- 2.20.1 ___ wayland-devel mailing list wayland-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/wayland-devel
[PATCH v5 11/11] tests: use fdescfs at *BSD to count fds
Signed-off-by: Leonid Bobrov --- tests/test-helpers.c | 11 --- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/test-helpers.c b/tests/test-helpers.c index f0c5b28..137c0b8 100644 --- a/tests/test-helpers.c +++ b/tests/test-helpers.c @@ -47,6 +47,11 @@ #else #include #include +# ifdef __linux__ +# define OPEN_FDS_DIR "/proc/self/fd" +# else +# define OPEN_FDS_DIR "/dev/fd" +# endif #endif #include "test-runner.h" @@ -75,8 +80,8 @@ count_open_fds(void) struct dirent *ent; int count = 0; - dir = opendir("/proc/self/fd"); - assert(dir && "opening /proc/self/fd failed."); + dir = opendir(OPEN_FDS_DIR); + assert(dir && "opening " OPEN_FDS_DIR " failed."); errno = 0; while ((ent = readdir(dir))) { @@ -85,7 +90,7 @@ count_open_fds(void) continue; count++; } - assert(errno == 0 && "reading /proc/self/fd failed."); + assert(errno == 0 && "reading " OPEN_FDS_DIR " failed."); closedir(dir); -- 2.20.1 ___ wayland-devel mailing list wayland-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/wayland-devel
[PATCH v5 08/11] tests: add OS-specific tracing to runner
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 b8f30e4..19ac93c 100644 --- a/configure.ac +++ b/configure.ac @@ -92,6 +92,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 v5 10/11] tests: use OpenBSD replacement for proc
Signed-off-by: Leonid Bobrov --- Makefile.am | 1 + configure.ac | 12 tests/test-helpers.c | 33 +++-- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index 6eefc73..44b58c4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -216,6 +216,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 65cc543..50e4e13 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 OpenBSD +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_CHECK_HEADERS([sys/epoll.h]) if test "x$ac_cv_header_sys_epoll_h" != "xyes"; then AC_CHECK_HEADERS([sys/event.h]) diff --git a/tests/test-helpers.c b/tests/test-helpers.c index b2189d8..f0c5b28 100644 --- a/tests/test-helpers.c +++ b/tests/test-helpers.c @@ -26,8 +26,6 @@ #include "config.h" #include -#include -#include #include #include #include @@ -37,12 +35,42 @@ #ifdef HAVE_SYS_PRCTL_H #include #endif +#ifdef HAVE_SYS_PARAM_H +#include +#endif +#ifdef __OpenBSD__ +#include +#include +#include +#include +#include +#else +#include +#include +#endif #include "test-runner.h" int count_open_fds(void) { +#ifdef __OpenBSD__ + /* Use OpenBSD-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 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 v5 05/11] core: define SO_PEERCRED if it's not defined
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 86685e0..08b38bd 100644 --- a/src/wayland-os.h +++ b/src/wayland-os.h @@ -41,6 +41,9 @@ wl_os_event_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 v5 07/11] server: add *BSD credentials support
Signed-off-by: Leonid Bobrov --- configure.ac | 2 ++ src/wayland-server.c | 35 +++ src/wayland-shm.c| 10 ++ 3 files changed, 47 insertions(+) diff --git a/configure.ac b/configure.ac index 414bc92..b8f30e4 100644 --- a/configure.ac +++ b/configure.ac @@ -73,6 +73,8 @@ if test "x$ac_cv_header_sys_epoll_h" != "xyes"; then fi fi +# Credential support on BSD +AC_CHECK_HEADERS([sys/ucred.h]) # *BSD don't have libdl, but they have its functions 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 v5 03/11] client: define EPROTO if it's not defined
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 v5 04/11] core: add kqueue support
Signed-off-by: Leonid Bobrov --- Makefile.am | 3 +- configure.ac | 23 +- doc/doxygen/Makefile.am | 3 +- src/{event-loop.c => event-loop-epoll.c} | 6 +- 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, 920 insertions(+), 19 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 489f581..6eefc73 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 f53408a..cf8d82d 100644 --- a/configure.ac +++ b/configure.ac @@ -65,6 +65,15 @@ AC_SUBST(GCC_CFLAGS) AC_CHECK_HEADERS([sys/prctl.h]) AC_CHECK_FUNCS([accept4 mkostemp posix_fallocate prctl]) +AC_CHECK_HEADERS([sys/epoll.h]) +if test "x$ac_cv_header_sys_epoll_h" != "xyes"; then + AC_CHECK_HEADERS([sys/event.h]) + if 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 +fi + + # *BSD don't have libdl, but they have its functions SAVE_LIBS="$LIBS" LIBS= @@ -116,12 +125,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..4784f64 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 @@ -523,7 +526,7 @@ wl_event_loop_create(void) if (loop == NULL) return NULL; - loop->epoll_fd = wl_os_epoll_create_cloexec(); + loop->epoll_fd = wl_os_event_create_cloexec(); if (loop->epoll_fd < 0) { free(loop); return NULL; @@ -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..3149f53 --- /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 limitatio
[PATCH v5 06/11] tests: support waitpid()
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 cf8d82d..414bc92 100644 --- a/configure.ac +++ b/configure.ac @@ -90,6 +90,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 v5 01/11] 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 | 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 v5 02/11] configure: detect libdl and librt
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 v5 09/11] shm: use workaround if mremap() is not available
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 19ac93c..65cc543 100644 --- a/configure.ac +++ b/configure.ac @@ -95,6 +95,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 v4 10/10] shm: use workaround if mremap() is not available
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 v4 08/10] server: add *BSD credentials support
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 v4 01/10] 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 | 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 v4 03/10] client: define EPROTO if it's not defined
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 v4 05/10] core: support kqueue
Signed-off-by: Leonid Bobrov --- Makefile.am | 3 +- configure.ac | 19 +- doc/doxygen/Makefile.am | 3 +- src/{event-loop.c => event-loop-epoll.c} | 6 +- 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, 916 insertions(+), 19 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..88013f0 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 @@ -523,7 +526,7 @@ wl_event_loop_create(void) if (loop == NULL) return NULL; - loop->epoll_fd = wl_os_epoll_create_cloexec(); + loop->epoll_fd = wl_os_queue_create_cloexec(); if (loop->epoll_fd < 0) { free(loop); return NULL; @@ -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..7d07d19 --- /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, + * distrib
[PATCH v4 04/10] tests: use *BSD replacement for /proc
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 v4 09/10] tests: add OS-specific tracing to runner
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 v4 07/10] tests: support waitpid()
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 v4 02/10] configure: detect libdl and librt
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 v4 06/10] core: define SO_PEERCRED if it's not defined
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 v3 03/10] client: define EPROTO if it's not defined
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
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
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 + * po
[PATCH v3 09/10] tests: add OS-specific tracing to runner
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
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
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
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
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()
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
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()
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
--- 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
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 + * po
[PATCH v2 4/9] tests: use *BSD replacement for /proc
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
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
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
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
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
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
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
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
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
--- 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()
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
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
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
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 + * po
[PATCH 2/9] configure: detect libdl and librt
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
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
--- 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
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
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
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 + * po
[PATCH 1/6] 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 ___ wayland-devel mailing list wayland-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/wayland-devel
[PATCH 8/8] configure: detect libdl and librt
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
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. +
[PATCH 6/8] client: define EPROTO if it's not defined
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()
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;
[PATCH 4/8] gitignore: ignore *.orig files generated by patch(1)
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.
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. */ +
[PATCH 2/8] tests: use *BSD replacement for /proc
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
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
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_LDAD
Re: tests: fix main symbol duplication
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
Re: tests: fix main symbol duplication
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
tests: fix main symbol duplication
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 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 +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_LDAD
Re: Few patches from Ravenports for DragonFly BSD support
On Thu, Jan 24, 2019 at 12:53:28PM +0200, Pekka Paalanen wrote: > Hi, > > you need to split this into logical patches, each patch doing one > logical thing. It is not the same as one patch per file. Each patch > needs to have a commit message explaining why the patch was written, > and so on. Please, see > https://gitlab.freedesktop.org/wayland/wayland/blob/master/CONTRIBUTING.md > Ok. > As for merging, I think I saw some bits that don't actually need any > #ifdef BSD guards but would be good fixes regardless of the OS. Patches > that do not depend on a specific OS I think we can land without having > a BSD in CI, but patches that depend on being built on a BSD should > come with CI. I won't personally have the time to figure out how to run > a BSD in Gitlab CI, someone else needs to write the patch. > > It would also be good to instead of hardcoding things like > #if Dragonfly /* no mremap */ to have autoconf test for the existence of > mremap, since the fallback to munmap+mmap seems quite generic. > Ok, I'll resend after Gitlab CI will be set up. Meanwhile I'll make sure this patch gets to Ravenports: https://github.com/mazocomp/openbsd-wip/blob/master/graphics/wayland/patches/patch-src_wayland-shm_c#L43 > > Thanks, > pq ___ wayland-devel mailing list wayland-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/wayland-devel
Few patches from Ravenports for DragonFly BSD support
From 660f1a59a0ff09f1c21e97087b713d6751e3de10 Mon Sep 17 00:00:00 2001 From: Leonid Bobrov Date: Sun, 20 Jan 2019 07:33:46 +0200 Subject: [PATCH] Few patches from Ravenports for DragonFly BSD support Taken from https://github.com/jrmarino/ravensource/tree/master/bucket_D7/wayland/patches --- cursor/wayland-cursor.c | 4 src/scanner.c | 2 +- src/wayland-server.c| 34 +++--- src/wayland-util.c | 1 + tests/test-compositor.c | 26 -- tests/test-runner.c | 33 + 6 files changed, 94 insertions(+), 6 deletions(-) diff --git a/cursor/wayland-cursor.c b/cursor/wayland-cursor.c index d40c5c8..51f9266 100644 --- a/cursor/wayland-cursor.c +++ b/cursor/wayland-cursor.c @@ -98,7 +98,11 @@ shm_pool_resize(struct shm_pool *pool, int size) pool->data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, pool->fd, 0); +#if defined(__DragonFly__) + if (pool->data == MAP_FAILED) +#else if (pool->data == (void *)-1) +#endif return 0; pool->size = size; diff --git a/src/scanner.c b/src/scanner.c index a94be5d..ac07473 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -1956,7 +1956,7 @@ int main(int argc, char *argv[]) buf = XML_GetBuffer(ctx.parser, XML_BUFFER_SIZE); len = fread(buf, 1, XML_BUFFER_SIZE, input); if (len < 0) { - fprintf(stderr, "fread: %m\n"); + fprintf(stderr, "fread: %s\n", strerror(errno)); fclose(input); exit(EXIT_FAILURE); } diff --git a/src/wayland-server.c b/src/wayland-server.c index eae8d2e..cc6229f 100644 --- a/src/wayland-server.c +++ b/src/wayland-server.c @@ -43,6 +43,13 @@ #include #include +#include "../config.h" + +#ifdef HAVE_SYS_UCRED_H +#include +#include +#endif + #include "wayland-util.h" #include "wayland-private.h" #include "wayland-server.h" @@ -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; }; @@ -303,7 +314,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); } @@ -502,7 +517,9 @@ WL_EXPORT struct wl_client * wl_client_create(struct wl_display *display, int fd) { struct wl_client *client; +#ifndef HAVE_SYS_UCRED_H socklen_t len; +#endif client = zalloc(sizeof *client); if (client == NULL) @@ -517,10 +534,12 @@ wl_client_create(struct wl_display *display, int fd) if (!client->source) goto err_client; +#ifndef HAVE_SYS_UCRED_H 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) @@ -574,12 +593,21 @@ 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 + if (pid) + *pid = 0; + 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 @@ -1329,7 +1357,7 @@ socket_data(int fd, uint32_t mask, void *data) client_fd = wl_os_accept_cloexec(fd, (struct sockaddr *) &name, &length); if (client_fd < 0) - wl_log("failed to accept: %m\n"); + wl_log("failed to accept: %s\n", strerror(errno)); else if (!wl_client_create(display, client_fd)) close(client_fd); @@ -1434,12 +1462,12 @@ _wl_display_add_socket(struct wl_display *display, struct wl_socket *s) size = offsetof (struct sockaddr_un, sun_path) + strlen(s->addr.sun_path); if (bind(s->fd, (struct sockaddr *) &s->addr, size) < 0) { - wl_log("bind() failed with error: %m\n&qu