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,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 = '/';
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user