diff options
Diffstat (limited to 'shared/os-compatibility.c')
-rw-r--r-- | shared/os-compatibility.c | 47 |
1 files changed, 4 insertions, 43 deletions
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; |