Fix the race between the stat() and the mkdir().
Reviewed by: jkh
This commit is contained in:
parent
e105123179
commit
076172c5bc
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=90266
@ -173,17 +173,13 @@ build(char *path, mode_t omode)
|
||||
}
|
||||
if (last)
|
||||
(void)umask(oumask);
|
||||
if (stat(path, &sb)) {
|
||||
if (errno != ENOENT ||
|
||||
mkdir(path, last ? omode :
|
||||
S_IRWXU | S_IRWXG | S_IRWXO) < 0) {
|
||||
if (mkdir(path, last ? omode : S_IRWXU | S_IRWXG | S_IRWXO) < 0) {
|
||||
if (errno == EEXIST) {
|
||||
if (stat(path, &sb) < 0) {
|
||||
warn("%s", path);
|
||||
retval = 1;
|
||||
break;
|
||||
} else if (vflag)
|
||||
printf("%s\n", path);
|
||||
}
|
||||
else if ((sb.st_mode & S_IFMT) != S_IFDIR) {
|
||||
} else if (!S_ISDIR(sb.st_mode)) {
|
||||
if (last)
|
||||
errno = EEXIST;
|
||||
else
|
||||
@ -192,6 +188,13 @@ build(char *path, mode_t omode)
|
||||
retval = 1;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
warn("%s", path);
|
||||
retval = 1;
|
||||
break;
|
||||
}
|
||||
} else if (vflag)
|
||||
printf("%s\n", path);
|
||||
if (!last)
|
||||
*p = '/';
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user