diff --git a/bar/wayland.c b/bar/wayland.c index 16af9fe..696f598 100644 --- a/bar/wayland.c +++ b/bar/wayland.c @@ -9,9 +9,7 @@ #include #include -#ifdef __linux__ -#include -#endif +#include #include #include @@ -771,7 +769,16 @@ get_buffer(struct wayland_backend *backend) pixman_image_t *pix = NULL; /* Backing memory for SHM */ +#if defined(MEMFD_CREATE) pool_fd = memfd_create("yambar-wayland-shm-buffer-pool", MFD_CLOEXEC); +#elif defined(__FreeBSD__) + // memfd_create on FreeBSD 13 is SHM_ANON without sealing support + pool_fd = shm_open(SHM_ANON, O_RDWR | O_CLOEXEC, 0600); +#else + char name[] = "/tmp/yambar-wayland-shm-buffer-pool-XXXXXX"; + pool_fd = mkostemp(name, O_CLOEXEC); + unlink(name); +#endif if (pool_fd == -1) { LOG_ERRNO("failed to create SHM backing memory file"); goto err; diff --git a/meson.build b/meson.build index 1970ec4..ed4d0d1 100644 --- a/meson.build +++ b/meson.build @@ -12,6 +12,10 @@ plugs_as_libs = get_option('core-plugins-as-shared-libraries') cc = meson.get_compiler('c') +if cc.has_function('memfd_create') + add_project_arguments('-DMEMFD_CREATE', language: 'c') +endif + # Compute the relative path used by compiler invocations. source_root = meson.current_source_dir().split('/') build_root = meson.build_root().split('/')