blob: 2cb76411e5a2ff78617a993fd5a50dfabde520ca [file] [edit]
From 780814273e8d8b1dc072bc8c4bb5981d2447a036 Mon Sep 17 00:00:00 2001
From: Stephen Barber <smbarber@chromium.org>
Date: Wed, 25 Oct 2017 16:19:56 -0700
Subject: [PATCH] HACK: use virtwl ioctl for allocation
---
cursor/os-compatibility.c | 71 ++++++++++++-----------------------------------
1 file changed, 17 insertions(+), 54 deletions(-)
diff --git a/cursor/os-compatibility.c b/cursor/os-compatibility.c
index d7d4b33..73101e7 100644
--- a/cursor/os-compatibility.c
+++ b/cursor/os-compatibility.c
@@ -25,17 +25,20 @@
#define _GNU_SOURCE
+#include <sys/ioctl.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
+#include <stdint.h>
+
+#include <linux/virtwl.h>
#include "config.h"
#include "os-compatibility.h"
-#ifndef HAVE_MKOSTEMP
static int
set_cloexec_or_close(int fd)
{
@@ -57,27 +60,6 @@ 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
@@ -103,46 +85,27 @@ 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;
+ struct virtwl_ioctl_new virtwl_ioctl_new = {
+ .type = VIRTWL_IOCTL_NEW_ALLOC,
+ .fd = -1,
+ .flags = 0,
+ .size = size
+ };
+ int wl_fd = -1;
int fd;
int ret;
- path = getenv("XDG_RUNTIME_DIR");
- if (!path) {
- errno = ENOENT;
- return -1;
- }
-
- name = malloc(strlen(path) + sizeof(template));
- if (!name)
+ wl_fd = open("/dev/wl0", O_RDWR);
+ if (wl_fd < 0)
return -1;
- strcpy(name, path);
- strcat(name, template);
-
- fd = create_tmpfile_cloexec(name);
+ ret = ioctl(wl_fd, VIRTWL_IOCTL_NEW, &virtwl_ioctl_new);
+ close(wl_fd);
- free(name);
-
- if (fd < 0)
+ if (ret)
return -1;
-#ifdef HAVE_POSIX_FALLOCATE
- ret = posix_fallocate(fd, 0, size);
- if (ret != 0) {
- close(fd);
- errno = ret;
- return -1;
- }
-#else
- ret = ftruncate(fd, size);
- if (ret < 0) {
- close(fd);
- return -1;
- }
-#endif
+ fd = set_cloexec_or_close(virtwl_ioctl_new.fd);
return fd;
}
--
2.15.0.rc2.357.g7e34df9404-goog