From 63b5aba984bf58c541855dceb241d0be317125f3 Mon Sep 17 00:00:00 2001 From: Roger Pau Monne Date: Tue, 23 Sep 2014 13:06:15 +0200 Subject: [PATCH] install: fix race when creating a directory Running two install commands in parallel with the same target directory could trigger a race if both try to create the directory at the same time. Add a retry case if mkdir fails with EEXIST in order to catch this. Sponsored by: Citrix Systems R&D MFC after: 3 days --- usr.bin/xinstall/xinstall.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/usr.bin/xinstall/xinstall.c b/usr.bin/xinstall/xinstall.c index f40cdc5..c1dd4b7 100644 --- a/usr.bin/xinstall/xinstall.c +++ b/usr.bin/xinstall/xinstall.c @@ -1263,8 +1263,11 @@ install_dir(char *path) if (!*p || (p != path && *p == '/')) { ch = *p; *p = '\0'; +again: if (stat(path, &sb)) { if (errno != ENOENT || mkdir(path, 0755) < 0) { + if (errno == EEXIST) + goto again; err(EX_OSERR, "mkdir %s", path); /* NOTREACHED */ } else if (verbose) -- 1.9.3 (Apple Git-50)