]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Fix race condition when creating initial cache directory
authorDavid Givone <david@givone.net>
Fri, 21 Sep 2012 05:01:09 +0000 (22:01 -0700)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 23 Sep 2012 18:03:04 +0000 (20:03 +0200)
util.c

diff --git a/util.c b/util.c
index 6782a881b411dd556184ef22e19b7ab18ee08402..ecb0a07bb91f9b513b144dee9da7167c7cdfb8eb 100644 (file)
--- a/util.c
+++ b/util.c
@@ -467,6 +467,18 @@ create_parent_dirs(const char *path)
                res = create_parent_dirs(parent);
                if (res == 0) {
                        res = mkdir(parent, 0777);
+                       /* Have to handle the condition of the directory already existing because
+                        * the file system could have changed in between calling stat and
+                        * actually creating the directory. This can happen when there are
+                        * multiple instances of ccache running and trying to create the same
+                        * directory chain, which usually is the case when the cache root does
+                        * not initially exist. As long as one of the processes creates the
+                        * directories then our condition is satisfied and we avoid a race
+                        * condition.
+                        */
+                       if (res != 0 && errno == EEXIST) {
+                               res = 0;
+                       }
                } else {
                        res = -1;
                }