Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[patch] Avoid race in zf_mkdir



A user reported in #zsh they were seeing sporadic zf_mkdir errors when
concurrently creating the same directory. Move the stat ISDIR check to
after the mkdir call to avoid the race.


diff --git a/Src/Modules/files.c b/Src/Modules/files.c
index 6d20e38a8..ae301c14f 100644
--- a/Src/Modules/files.c
+++ b/Src/Modules/files.c
@@ -124,17 +124,17 @@ domkdir(char *nam, char *path, mode_t mode, int p)
     mode_t oumask;
     char const *rpath = unmeta(path);
 
+    oumask = umask(0);
+    err = mkdir(rpath, mode) ? errno : 0;
+    umask(oumask);
+    if(!err)
+	return 0;
     if(p) {
 	struct stat st;
 
 	if(!stat(rpath, &st) && S_ISDIR(st.st_mode))
 	    return 0;
     }
-    oumask = umask(0);
-    err = mkdir(rpath, mode) ? errno : 0;
-    umask(oumask);
-    if(!err)
-	return 0;
     zwarnnam(nam, "cannot make directory `%s': %e", path, err);
     return 1;
 }




Messages sorted by: Reverse Date, Date, Thread, Author