diff options
author | Sébastien Marie <semarie@online.fr> | 2024-01-19 16:09:27 +0000 |
---|---|---|
committer | Daniel Stone <daniels@collabora.com> | 2024-02-21 15:46:41 +0000 |
commit | d80bce5f1a0917c013aac54e3f951ffe740d0cbe (patch) | |
tree | 23e5acea8fc607c4e6dab825b529a352941d9aec | |
parent | 791912c67867b84e15f7a70d5f716c9dd8c2c01b (diff) |
build: fix build and provide compat for OpenBSD
- wayland-egl-abi-check: try to use llvm-nm first instead of BSD nm (incompatible options)
- avoid forcing _POSIX_C_SOURCE=200809L (SOCK_CLOEXEC become available)
- epoll(7) is provided by a userspace wrapper around kqueue(2) as FreeBSD
- when using SO_PEERCRED, the struct to use is `struct sockpeercred` instead of `struct ucred` on OpenBSD
- provide a compatibility layer for count_open_fds() using sysctl(2) as FreeBSD
Signed-off-by: Sebastien Marie <semarie@online.fr>
-rw-r--r-- | egl/meson.build | 2 | ||||
-rw-r--r-- | meson.build | 4 | ||||
-rw-r--r-- | src/wayland-os.c | 4 | ||||
-rw-r--r-- | tests/test-helpers.c | 27 | ||||
-rw-r--r-- | tests/test-runner.c | 7 |
5 files changed, 41 insertions, 3 deletions
diff --git a/egl/meson.build b/egl/meson.build index 76c6ee2..5c62ac1 100644 --- a/egl/meson.build +++ b/egl/meson.build @@ -13,7 +13,7 @@ if get_option('tests') wayland_egl_abi_check = executable('wayland-egl-abi-check', 'wayland-egl-abi-check.c') test('wayland-egl abi check', wayland_egl_abi_check) - nm_path = find_program('nm').full_path() + nm_path = find_program(['llvm-nm', 'nm']).full_path() test( 'wayland-egl symbols check', diff --git a/meson.build b/meson.build index b879df7..431ebb7 100644 --- a/meson.build +++ b/meson.build @@ -16,7 +16,7 @@ config_h.set_quoted('PACKAGE', meson.project_name()) config_h.set_quoted('PACKAGE_VERSION', meson.project_version()) cc_args = [] -if host_machine.system() != 'freebsd' +if host_machine.system() not in ['freebsd', 'openbsd'] cc_args += ['-D_POSIX_C_SOURCE=200809L'] endif add_project_arguments(cc_args, language: 'c') @@ -69,7 +69,7 @@ endif config_h.set10('HAVE_BROKEN_MSG_CMSG_CLOEXEC', have_broken_msg_cmsg_cloexec) if get_option('libraries') - if host_machine.system() == 'freebsd' + if host_machine.system() in ['freebsd', 'openbsd'] # When building for FreeBSD, epoll(7) is provided by a userspace # wrapper around kqueue(2). epoll_dep = dependency('epoll-shim') diff --git a/src/wayland-os.c b/src/wayland-os.c index a0db2e8..f00ead4 100644 --- a/src/wayland-os.c +++ b/src/wayland-os.c @@ -111,7 +111,11 @@ int wl_os_socket_peercred(int sockfd, uid_t *uid, gid_t *gid, pid_t *pid) { socklen_t len; +#if defined(__OpenBSD__) + struct sockpeercred ucred; +#else struct ucred ucred; +#endif len = sizeof(ucred); if (getsockopt(sockfd, SOL_SOCKET, SO_PEERCRED, &ucred, &len) < 0) diff --git a/tests/test-helpers.c b/tests/test-helpers.c index 3535744..1af813b 100644 --- a/tests/test-helpers.c +++ b/tests/test-helpers.c @@ -61,6 +61,33 @@ count_open_fds(void) assert(error == 0 && "sysctl KERN_PROC_NFDS failed."); return nfds; } +#elif defined(__OpenBSD__) +#include <sys/sysctl.h> + +/* + * On OpenBSD, get file descriptor information using sysctl() + */ +int +count_open_fds(void) +{ + int error; + int mib[6]; + size_t size; + + mib[0] = CTL_KERN; + mib[1] = KERN_FILE; + mib[2] = KERN_FILE_BYPID; + mib[3] = getpid(); + mib[4] = sizeof(struct kinfo_file); + mib[5] = 0; + + /* find the size required to store all the entries */ + error = sysctl(mib, 6, NULL, &size, NULL, 0); + assert(error != -1 && "sysctl KERN_FILE_BYPID failed."); + + /* return the current number of entries */ + return size / sizeof(struct kinfo_file); +} #else int count_open_fds(void) diff --git a/tests/test-runner.c b/tests/test-runner.c index ea2715e..9a50d1d 100644 --- a/tests/test-runner.c +++ b/tests/test-runner.c @@ -308,6 +308,13 @@ is_debugger_attached(void) return rc; } +#else +static int +is_debugger_attached(void) +{ + /* 0=debugger can't be determined */ + return 0; +} #endif int main(int argc, char *argv[]) |