diff options
author | Quentin Glidic <sardemff7+git@sardemff7.net> | 2017-10-17 14:31:10 +0200 |
---|---|---|
committer | Quentin Glidic <sardemff7+git@sardemff7.net> | 2017-10-17 15:01:57 +0200 |
commit | 9d60cf8bfb1b88b6d0e4a499d6877b0e7dbe17d6 (patch) | |
tree | 2a47d1222897c915b39e0029782f66fad4a3b6b3 | |
parent | 242005636d0897db166215ed09cf3832217df008 (diff) |
cursor: Use shm_open() instead of XDG_RUNTIME_DIR fileswip/shm_open
Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
-rw-r--r-- | cursor/os-compatibility.c | 68 |
1 files changed, 4 insertions, 64 deletions
diff --git a/cursor/os-compatibility.c b/cursor/os-compatibility.c index e972d21..69aeab9 100644 --- a/cursor/os-compatibility.c +++ b/cursor/os-compatibility.c @@ -26,6 +26,7 @@ #define _GNU_SOURCE #include <sys/types.h> +#include <sys/mman.h> #include <unistd.h> #include <fcntl.h> #include <errno.h> @@ -35,60 +36,13 @@ #include "config.h" #include "os-compatibility.h" -#ifndef HAVE_MKOSTEMP -static int -set_cloexec_or_close(int fd) -{ - long flags; - - if (fd == -1) - return -1; - - flags = fcntl(fd, F_GETFD); - if (flags == -1) - goto err; - - if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1) - goto err; - - return fd; - -err: - close(fd); - return -1; -} -#endif - -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 @@ -109,22 +63,8 @@ os_create_anonymous_file(off_t size) 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("/wayland-cursor-shared", O_CREAT | O_RDWR, 0); + shm_unlink("/wayland-cursor-shared"); if (fd < 0) return -1; |