From 5fc73f8a190d143a5899a4b9ddb25c7930a04ca8 Mon Sep 17 00:00:00 2001 From: Quentin Glidic Date: Tue, 17 Oct 2017 14:55:21 +0200 Subject: shared: Use shm_open() instead of XDG_RUNTIME_DIR files Signed-off-by: Quentin Glidic --- Makefile.am | 4 ++++ clients/window.c | 3 +-- configure.ac | 2 ++ shared/os-compatibility.c | 47 ++++------------------------------------------- 4 files changed, 11 insertions(+), 45 deletions(-) diff --git a/Makefile.am b/Makefile.am index 9d99c694..fe02eb1e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1130,6 +1130,9 @@ libshared_la_SOURCES = \ shared/xalloc.c \ shared/xalloc.h +libshared_la_LIBADD = \ + $(SHM_OPEN_LIBS) + libshared_cairo_la_CFLAGS = \ -DDATADIR='"$(datadir)"' \ $(AM_CFLAGS) \ @@ -1140,6 +1143,7 @@ libshared_cairo_la_CFLAGS = \ $(WEBP_CFLAGS) libshared_cairo_la_LIBADD = \ + $(libshared_la_LIBADD) \ $(PIXMAN_LIBS) \ $(CAIRO_LIBS) \ $(PNG_LIBS) \ diff --git a/clients/window.c b/clients/window.c index 95796d46..450310e3 100644 --- a/clients/window.c +++ b/clients/window.c @@ -4218,8 +4218,7 @@ undo_resize(struct window *window) if (window->pending_allocation.width == 0 && window->pending_allocation.height == 0) { fprintf(stderr, "Error: Could not draw a surface, " - "most likely due to insufficient disk space in " - "%s (XDG_RUNTIME_DIR).\n", getenv("XDG_RUNTIME_DIR")); + "most likely due to insufficient memory"); exit(EXIT_FAILURE); } } diff --git a/configure.ac b/configure.ac index c287fac6..e26d63bc 100644 --- a/configure.ac +++ b/configure.ac @@ -89,6 +89,8 @@ PKG_PROG_PKG_CONFIG() # Check for dlsym instead of dlopen because ASAN hijacks the latter WESTON_SEARCH_LIBS([DL], [dl], [dlsym]) +WESTON_SEARCH_LIBS([SHM_OPEN], [rt], [shm_open]) + # In old glibc versions (< 2.17) clock_gettime() and clock_getres() are in librt WESTON_SEARCH_LIBS([CLOCK_GETTIME], [rt], [clock_gettime]) WESTON_SEARCH_LIBS([CLOCK_GETRES], [rt], [clock_getres]) diff --git a/shared/os-compatibility.c b/shared/os-compatibility.c index e19fb61b..24298630 100644 --- a/shared/os-compatibility.c +++ b/shared/os-compatibility.c @@ -26,6 +26,7 @@ #include "config.h" #include +#include #include #include #include @@ -107,36 +108,13 @@ os_epoll_create_cloexec(void) return set_cloexec_or_close(fd); } -static int -create_tmpfile_cloexec(char *tmpname) -{ - int fd; - -#ifdef HAVE_MKOSTEMP - fd = mkostemp(tmpname, O_CLOEXEC); - if (fd >= 0) - unlink(tmpname); -#else - fd = mkstemp(tmpname); - if (fd >= 0) { - fd = set_cloexec_or_close(fd); - unlink(tmpname); - } -#endif - - return fd; -} - /* * Create a new, unique, anonymous file of the given size, and * return the file descriptor for it. The file descriptor is set * CLOEXEC. The file is immediately suitable for mmap()'ing * the given size at offset zero. * - * The file should not have a permanent backing store like a disk, - * but may have if XDG_RUNTIME_DIR is not properly implemented in OS. - * - * The file name is deleted from the file system. + * The file will not have a permanent backing store like a disk. * * The file is suitable for buffer sharing between processes by * transmitting the file descriptor over Unix sockets using the @@ -151,28 +129,11 @@ create_tmpfile_cloexec(char *tmpname) int os_create_anonymous_file(off_t size) { - static const char template[] = "/weston-shared-XXXXXX"; - const char *path; - char *name; int fd; int ret; - path = getenv("XDG_RUNTIME_DIR"); - if (!path) { - errno = ENOENT; - return -1; - } - - name = malloc(strlen(path) + sizeof(template)); - if (!name) - return -1; - - strcpy(name, path); - strcat(name, template); - - fd = create_tmpfile_cloexec(name); - - free(name); + fd = shm_open("/weston-shared", O_CREAT | O_RDWR, 0); + shm_unlink("/weston-shared"); if (fd < 0) return -1; -- cgit v1.2.3