zsh-workers
 help / color / mirror / code / Atom feed
* [patch] Avoid race in zf_mkdir
@ 2020-10-09 20:07 Matthew Martin
  2020-10-09 20:24 ` Bart Schaefer
  0 siblings, 1 reply; 14+ messages in thread
From: Matthew Martin @ 2020-10-09 20:07 UTC (permalink / raw)
  To: zsh-workers

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;
 }


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2020-10-22 13:31 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-09 20:07 [patch] Avoid race in zf_mkdir Matthew Martin
2020-10-09 20:24 ` Bart Schaefer
2020-10-09 20:35   ` Roman Perepelitsa
2020-10-09 20:47     ` Bart Schaefer
2020-10-09 20:53       ` Matthew Martin
2020-10-09 21:22         ` Roman Perepelitsa
2020-10-09 21:27           ` Bart Schaefer
2020-10-10 11:50             ` Roman Perepelitsa
2020-10-15 10:01               ` Roman Perepelitsa
2020-10-15 15:29                 ` Bart Schaefer
2020-10-15 15:36                   ` Roman Perepelitsa
2020-10-15 16:47                     ` Bart Schaefer
2020-10-22 13:30                     ` Roman Perepelitsa
2020-10-09 21:40           ` Matthew Martin

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).