[mutter/wip/wayland] squash: Use g_file_open_tmp instead of mkostemp
- From: Neil Roberts <nroberts src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/wip/wayland] squash: Use g_file_open_tmp instead of mkostemp
- Date: Wed, 24 Jul 2013 16:16:03 +0000 (UTC)
commit ec36cffaba527d75a54d1eaa26e782de546297a1
Author: Neil Roberts <neil linux intel com>
Date: Wed Jul 24 14:47:34 2013 +0100
squash: Use g_file_open_tmp instead of mkostemp
glib has a wrapper for mkstemp which is slightly more convenient.
However this isn't quite as robust as mkostemp because there would be
a race condition to set CLOEXEC on the fd if another thread forks
before it is set. However I don't think this is really a problem for
mutter.
This should be squashed into the patch
“wayland: Add basic input support”
configure.ac | 2 -
src/wayland/meta-wayland-keyboard.c | 81 ++++++++--------------------------
2 files changed, 19 insertions(+), 64 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index dabe507..f83f584 100644
--- a/configure.ac
+++ b/configure.ac
@@ -139,8 +139,6 @@ AC_ARG_WITH([xwayland-path],
[XWAYLAND_PATH="$withval"],
[XWAYLAND_PATH="$bindir/Xorg"])
-AC_CHECK_FUNCS([mkostemp])
-
AM_GLIB_GNU_GETTEXT
## here we get the flags we'll actually use
diff --git a/src/wayland/meta-wayland-keyboard.c b/src/wayland/meta-wayland-keyboard.c
index b6d31ff..517cd78 100644
--- a/src/wayland/meta-wayland-keyboard.c
+++ b/src/wayland/meta-wayland-keyboard.c
@@ -67,16 +67,22 @@ meta_wayland_keyboard_get_seat (MetaWaylandKeyboard *keyboard)
return seat;
}
-#ifndef HAVE_MKOSTEMP
-
static int
-set_cloexec_or_close (int fd)
+create_anonymous_file (off_t size,
+ GError **error)
{
- long flags;
+ static const char template[] = "weston-shared-XXXXXX";
+ char *path;
+ int fd, flags;
+
+ fd = g_file_open_tmp (template, &path, error);
if (fd == -1)
return -1;
+ unlink (path);
+ g_free (path);
+
flags = fcntl (fd, F_GETFD);
if (flags == -1)
goto err;
@@ -84,68 +90,19 @@ set_cloexec_or_close (int fd)
if (fcntl (fd, F_SETFD, flags | FD_CLOEXEC) == -1)
goto err;
- return fd;
-
-err:
- close (fd);
- return -1;
-}
-
-#endif /* HAVE_MKOSTEMP */
-
-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
+ if (ftruncate (fd, size) < 0)
+ goto err;
return fd;
-}
-static int
-create_anonymous_file (off_t size,
- GError **error)
-{
- static const char template[] = "weston-shared-XXXXXX";
- const char *path;
- char *name;
- int fd;
-
- path = g_getenv ("XDG_RUNTIME_DIR");
- if (!path)
- {
- errno = ENOENT;
- return -1;
- }
-
- name = g_build_filename (path, template, NULL);
-
- fd = create_tmpfile_cloexec (name);
-
- free (name);
-
- if (fd < 0)
- return -1;
-
- if (ftruncate (fd, size) < 0)
- {
- close (fd);
- return -1;
- }
+ err:
+ g_set_error_literal (error,
+ G_FILE_ERROR,
+ g_file_error_from_errno (errno),
+ strerror (errno));
+ close (fd);
- return fd;
+ return -1;
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]