From 0e6b9ee838cf6370c2c8e3ea723839c383de96cc Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Tue, 29 Nov 2011 13:32:27 -0800 Subject: [PATCH] build - install should not complain if the mkdir() races * install should not complain if the mkdir() races * A make -j N can cause concurrent install's to race their mkdir() calls. --- usr.bin/xinstall/xinstall.c | 22 +++++++++++++++++++++- 1 files changed, 21 insertions(+), 1 deletions(-) diff --git a/usr.bin/xinstall/xinstall.c b/usr.bin/xinstall/xinstall.c index a1add6d..0484383 100644 --- a/usr.bin/xinstall/xinstall.c +++ b/usr.bin/xinstall/xinstall.c @@ -813,6 +813,25 @@ strip(const char *to_name) } /* + * When doing a concurrent make -j N multiple install's can race the mkdir. + */ +static +int +mkdir_race(const char *path, int nmode) +{ + int res; + struct stat sb; + + res = mkdir(path, nmode); + if (res < 0 && errno == EEXIST) { + if (stat(path, &sb) == 0 && S_ISDIR(sb.st_mode)) + return(0); + res = mkdir(path, mode); + } + return (res); +} + +/* * install_dir -- * build directory hierarchy */ @@ -828,7 +847,8 @@ install_dir(char *path) ch = *p; *p = '\0'; if (stat(path, &sb)) { - if (errno != ENOENT || mkdir(path, 0755) < 0) { + if (errno != ENOENT || + mkdir_race(path, 0755) < 0) { err(EX_OSERR, "mkdir %s", path); /* NOTREACHED */ } else if (verbose) -- 1.7.7.2