Signed-off-by: Leonid Bobrov <mazoc...@disroot.org> --- 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 <assert.h> -#include <errno.h> -#include <dirent.h> #include <stdio.h> #include <unistd.h> #include <time.h> @@ -37,12 +35,42 @@ #ifdef HAVE_SYS_PRCTL_H #include <sys/prctl.h> #endif +#ifdef HAVE_SYS_PARAM_H +#include <sys/param.h> +#endif +#ifdef __OpenBSD__ +#include <sys/types.h> +#include <sys/sysctl.h> +#include <fcntl.h> +#include <kvm.h> +#include <limits.h> +#else +#include <errno.h> +#include <dirent.h> +#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