]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Set correct permission for stats, manifest and ccache.conf files
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 10 Dec 2014 17:40:38 +0000 (18:40 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 10 Dec 2014 17:40:38 +0000 (18:40 +0100)
This fixes a regression in a07f46a3b0f7e452d50690b831bb4c99fbc6650f and
fc61ca9a9232f26ee3f714d4b8738d916f6948ff where mkstemp was introduced for
creating temporary files. However, mkstemp creates files with 0600
permissions, which is bad for temporary files that are renamed to a
persistent name in the cache.

util.c

diff --git a/util.c b/util.c
index a375a4269204589d80570c818b399892cba18e84..80eb58b6e8d5b2c30e762f836eb944df5ed9ed01 100644 (file)
--- a/util.c
+++ b/util.c
@@ -223,6 +223,21 @@ mkstemp(char *template)
 }
 #endif
 
+#ifndef _WIN32
+static mode_t
+get_umask(void)
+{
+       static bool mask_retrieved = false;
+       static mode_t mask;
+       if (!mask_retrieved) {
+               mask = umask(0);
+               umask(mask);
+               mask_retrieved = true;
+       }
+       return mask;
+}
+#endif
+
 /*
  * Copy src to dest, decompressing src if needed. compress_level > 0 decides
  * whether dest will be compressed, and with which compression level.
@@ -235,9 +250,6 @@ copy_file(const char *src, const char *dest, int compress_level)
        char buf[10240];
        int n, written;
        char *tmp_name;
-#ifndef _WIN32
-       mode_t mask;
-#endif
        struct stat st;
        int errnum;
 
@@ -337,10 +349,7 @@ copy_file(const char *src, const char *dest, int compress_level)
        }
 
 #ifndef _WIN32
-       /* get perms right on the tmp file */
-       mask = umask(0);
-       fchmod(fd_out, 0666 & ~mask);
-       umask(mask);
+       fchmod(fd_out, 0666 & ~get_umask());
 #endif
 
        /* the close can fail on NFS if out of space */
@@ -1064,6 +1073,11 @@ create_tmp_fd(char **fname)
        if (fd == -1) {
                fatal("Failed to create file %s: %s", template, strerror(errno));
        }
+
+#ifndef _WIN32
+       fchmod(fd, 0666 & ~get_umask());
+#endif
+
        free(*fname);
        *fname = template;
        return fd;