[vte/vte-0-36] utils: Set some FS flags on our temp files



commit c33bed4f70315390195f51fe0981cf68b81a8bb3
Author: Christian Persch <chpe gnome org>
Date:   Fri Jun 13 19:13:56 2014 +0200

    utils: Set some FS flags on our temp files
    
    Disable COW on our temp files, if the FS it's on supports it.
    
    (cherry picked from commit 4b4cb33957749a2f194aeec63c1b17b4acd29c02)

 src/vteutils.c |   27 +++++++++++++++++++++++++--
 1 files changed, 25 insertions(+), 2 deletions(-)
---
diff --git a/src/vteutils.c b/src/vteutils.c
index f840b89..648d185 100644
--- a/src/vteutils.c
+++ b/src/vteutils.c
@@ -32,13 +32,18 @@
 
 /* Temporary define until glibc release catches up */
 #ifdef __linux__
+
+#include <sys/ioctl.h>
+#include <linux/fs.h>
+
 #ifndef O_TMPFILE
 #ifndef __O_TMPFILE
 #define __O_TMPFILE     020000000
 #endif
 #define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)
 #endif
-#endif
+
+#endif /* __linux__ */
 
 int
 _vte_mkstemp (void)
@@ -48,7 +53,7 @@ _vte_mkstemp (void)
 
 #ifdef O_TMPFILE
         fd = open (g_get_tmp_dir (),
-                   O_TMPFILE | O_EXCL | O_RDWR | O_NOATIME,
+                   O_TMPFILE | O_EXCL | O_RDWR | O_NOATIME | O_CLOEXEC,
                    0600);
         if (fd != -1)
                 goto done;
@@ -71,5 +76,23 @@ _vte_mkstemp (void)
  done:
 #endif
 
+#ifdef __linux__
+{
+        /* Mark the tmpfile as no-cow on file systems that support it.
+         *
+         * (Note that the definition of the ioctls make you think @flags would
+         * be long instead of int, but it turns out that this is not the case;
+         * see http://lwn.net/Articles/575846/ ).
+         */
+        int flags;
+
+        if (ioctl (fd, FS_IOC_GETFLAGS, &flags) == 0) {
+                flags |= FS_SECRM_FL | FS_NOATIME_FL | FS_NOCOMP_FL | FS_NOCOW_FL | FS_NODUMP_FL;
+
+                ioctl (fd, FS_IOC_SETFLAGS, &flags);
+        }
+}
+#endif /* __linux__ */
+
         return fd;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]