install: re-check failed mkdir for EEXIST
Since the code stats and mkdirs in 2 separate steps, it is possible that the directory will be created in the meantime by something else (e.g. concurrent install).[1] While here alter the code to properly report stat failure, previously it would always claim it was mkdir which failed. Noted by: royger [1] MFC after: 1 week
This commit is contained in:
parent
5a66f6b3c4
commit
6e633f7297
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=272026
@ -1263,11 +1263,16 @@ install_dir(char *path)
|
||||
if (!*p || (p != path && *p == '/')) {
|
||||
ch = *p;
|
||||
*p = '\0';
|
||||
if (stat(path, &sb)) {
|
||||
if (errno != ENOENT || mkdir(path, 0755) < 0) {
|
||||
again:
|
||||
if (stat(path, &sb) < 0) {
|
||||
if (errno != ENOENT)
|
||||
err(EX_OSERR, "stat %s", path);
|
||||
if (mkdir(path, 0755) < 0) {
|
||||
if (errno == EEXIST)
|
||||
goto again;
|
||||
err(EX_OSERR, "mkdir %s", path);
|
||||
/* NOTREACHED */
|
||||
} else if (verbose)
|
||||
}
|
||||
if (verbose)
|
||||
(void)printf("install: mkdir %s\n",
|
||||
path);
|
||||
} else if (!S_ISDIR(sb.st_mode))
|
||||
|
Loading…
Reference in New Issue
Block a user