summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Glidic <sardemff7+git@sardemff7.net>2017-10-17 14:55:21 +0200
committerQuentin Glidic <sardemff7+git@sardemff7.net>2017-10-17 15:03:26 +0200
commit5fc73f8a190d143a5899a4b9ddb25c7930a04ca8 (patch)
tree334b5c806e4db1da702f329cae8d1e88d62e8be8
parent71ebc052505732b26591b2a5bc5a8be9b7c3e09f (diff)
shared: Use shm_open() instead of XDG_RUNTIME_DIR fileswip/shm_open
Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
-rw-r--r--Makefile.am4
-rw-r--r--clients/window.c3
-rw-r--r--configure.ac2
-rw-r--r--shared/os-compatibility.c47
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 <sys/types.h>
+#include <sys/mman.h>
#include <sys/socket.h>
#include <unistd.h>
#include <fcntl.h>
@@ -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;