[Bf-blender-cvs] [a7a56cab3b3] temp-T97352-3d-texturing-seam-bleeding-b2: Cleanup: split memfd_create into it's own function for Wayland
Campbell Barton
noreply at git.blender.org
Mon Jul 11 15:36:21 CEST 2022
Commit: a7a56cab3b387ace1c97a78e2c7aee73a5bef016
Author: Campbell Barton
Date: Sat Jul 9 22:27:27 2022 +1000
Branches: temp-T97352-3d-texturing-seam-bleeding-b2
https://developer.blender.org/rBa7a56cab3b387ace1c97a78e2c7aee73a5bef016
Cleanup: split memfd_create into it's own function for Wayland
Avoid ifdef's in cursor loading by creating a memfd_create_sealed
utility function that works irrespective of memfd_create availability.
===================================================================
M intern/ghost/intern/GHOST_SystemWayland.cpp
===================================================================
diff --git a/intern/ghost/intern/GHOST_SystemWayland.cpp b/intern/ghost/intern/GHOST_SystemWayland.cpp
index 76e5329a410..25123fe651f 100644
--- a/intern/ghost/intern/GHOST_SystemWayland.cpp
+++ b/intern/ghost/intern/GHOST_SystemWayland.cpp
@@ -747,7 +747,30 @@ static const std::vector<std::string> mime_send = {
"text/plain",
};
-#undef LOG
+static int memfd_create_sealed(const char *name)
+{
+#ifdef HAVE_MEMFD_CREATE
+ const int fd = memfd_create(name, MFD_CLOEXEC | MFD_ALLOW_SEALING);
+ if (fd >= 0) {
+ fcntl(fd, F_ADD_SEALS, F_SEAL_SHRINK | F_SEAL_SEAL);
+ }
+ return fd;
+#else /* HAVE_MEMFD_CREATE */
+ char *path = getenv("XDG_RUNTIME_DIR");
+ if (!path) {
+ errno = ENOENT;
+ return -1;
+ }
+ char *tmpname;
+ asprintf(&tmpname, "%s/%s-XXXXXX", path, name);
+ const int fd = mkostemp(tmpname, O_CLOEXEC);
+ if (fd >= 0) {
+ unlink(tmpname);
+ }
+ free(tmpname);
+ return fd;
+#endif /* !HAVE_MEMFD_CREATE */
+}
/** \} */
@@ -3355,27 +3378,7 @@ GHOST_TSuccess GHOST_SystemWayland::setCustomCursorShape(uint8_t *bitmap,
static const int32_t stride = sizex * 4; /* ARGB */
cursor->file_buffer->size = (size_t)stride * sizey;
-#ifdef HAVE_MEMFD_CREATE
- const int fd = memfd_create("blender-cursor-custom", MFD_CLOEXEC | MFD_ALLOW_SEALING);
- if (fd >= 0) {
- fcntl(fd, F_ADD_SEALS, F_SEAL_SHRINK | F_SEAL_SEAL);
- }
-#else
- char *path = getenv("XDG_RUNTIME_DIR");
- if (!path) {
- errno = ENOENT;
- return GHOST_kFailure;
- }
-
- char *tmpname;
- asprintf(&tmpname, "%s/%s", path, "blender-XXXXXX");
- const int fd = mkostemp(tmpname, O_CLOEXEC);
- if (fd >= 0) {
- unlink(tmpname);
- }
- free(tmpname);
-#endif
-
+ const int fd = memfd_create_sealed("blender-cursor-custom");
if (UNLIKELY(fd < 0)) {
return GHOST_kFailure;
}
More information about the Bf-blender-cvs
mailing list