Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[patch] Avoid race in zf_mkdir
- X-seq: zsh-workers 47436
- From: Matthew Martin <phy1729@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: [patch] Avoid race in zf_mkdir
- Date: Fri, 9 Oct 2020 15:07:37 -0500
- Archived-at: <https://zsh.org/workers/47436>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-workers/2020-10/20201009200737.GA78914%40CptOrmolo.darkstar>
- Authentication-results: zsh.org; iprev=pass (mail-oo1-f50.google.com) smtp.remote-ip=209.85.161.50; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mail-followup-to:mime-version :content-disposition; bh=BcXVXzHp6ajQ0YVLRYBMn9DFFDQeKc2+WqBdZGZptkA=; b=IY6iA4xSZS5qu8eGq/2nKlnaCMRMFKwFbLYfq/pyGixRGkgtL12/hws+1X3gm3q96O nww+V70daZblqTnT14bEGCsAwaFSjBwF47eOo3+Gp5sDq8zua1hvo8ieYwz7xvQU0cvI 0oMAoijxAnxxldPQZpk51u9KlTwl/FO7FlTBmcJljvZUdLfM67Ynv8/iGRhdJckPeol8 7G9EqF+8Ka7YYOgkdn62x9/WQhVJT6Qw3WDaBMwGNVuZdgbSYsEMFZ4tMF4mU3uzdhtg bQxJTtBQzssnij3ZFuzxd8kccQhJlRMXz10svAYwo8qZu/klK5UwYuJwi/+U+TIlkkIT 0OJQ==
- List-archive: <http://www.zsh.org/sympa/arc/zsh-workers>
- List-help: <mailto:sympa@zsh.org?subject=help>
- List-id: <zsh-workers.zsh.org>
- List-owner: <mailto:zsh-workers-request@zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-subscribe: <mailto:sympa@zsh.org?subject=subscribe%20zsh-workers>
- List-unsubscribe: <mailto:sympa@zsh.org?subject=unsubscribe%20zsh-workers>
- Mail-followup-to: zsh-workers@xxxxxxx
- Sender: zsh-workers-request@xxxxxxx
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