Fix the race between the stat() and the mkdir().

Reviewed by:	jkh
This commit is contained in:
Dave Zarzycki 2002-02-05 21:55:12 +00:00
parent e105123179
commit 076172c5bc
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=90266

View File

@ -173,25 +173,28 @@ build(char *path, mode_t omode)
} }
if (last) if (last)
(void)umask(oumask); (void)umask(oumask);
if (stat(path, &sb)) { if (mkdir(path, last ? omode : S_IRWXU | S_IRWXG | S_IRWXO) < 0) {
if (errno != ENOENT || if (errno == EEXIST) {
mkdir(path, last ? omode : if (stat(path, &sb) < 0) {
S_IRWXU | S_IRWXG | S_IRWXO) < 0) { warn("%s", path);
retval = 1;
break;
} else if (!S_ISDIR(sb.st_mode)) {
if (last)
errno = EEXIST;
else
errno = ENOTDIR;
warn("%s", path);
retval = 1;
break;
}
} else {
warn("%s", path); warn("%s", path);
retval = 1; retval = 1;
break; break;
} else if (vflag) }
printf("%s\n", path); } else if (vflag)
} printf("%s\n", path);
else if ((sb.st_mode & S_IFMT) != S_IFDIR) {
if (last)
errno = EEXIST;
else
errno = ENOTDIR;
warn("%s", path);
retval = 1;
break;
}
if (!last) if (!last)
*p = '/'; *p = '/';
} }