diff options
author | Douglas Gregor <dgregor@apple.com> | 2013-01-10 01:58:46 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2013-01-10 01:58:46 +0000 |
commit | 95585ab6a44edc0a56eec3572684d6e72828fc0d (patch) | |
tree | fdd9568715a20a4795560ebabd9408fe8d58517d /llvm/lib | |
parent | 230203c9499991eb28f8926d0c96fe0b55b82ccb (diff) | |
download | bcm5719-llvm-95585ab6a44edc0a56eec3572684d6e72828fc0d.tar.gz bcm5719-llvm-95585ab6a44edc0a56eec3572684d6e72828fc0d.zip |
Fix a race condition in llvm::sys::path::unique_file: when we end up
failing to create the unique file because the path doesn't exist,
don't fail if someone else manages to create the path before we do.
llvm-svn: 172032
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Support/Unix/PathV2.inc | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/llvm/lib/Support/Unix/PathV2.inc b/llvm/lib/Support/Unix/PathV2.inc index 25712a8a9f0..741f44a9db8 100644 --- a/llvm/lib/Support/Unix/PathV2.inc +++ b/llvm/lib/Support/Unix/PathV2.inc @@ -421,11 +421,12 @@ retry_random_path: rety_open_create: int RandomFD = ::open(RandomPath.c_str(), O_RDWR | O_CREAT | O_EXCL, mode); if (RandomFD == -1) { + int SavedErrno = errno; // If the file existed, try again, otherwise, error. - if (errno == errc::file_exists) + if (SavedErrno == errc::file_exists) goto retry_random_path; // If path prefix doesn't exist, try to create it. - if (errno == errc::no_such_file_or_directory && + if (SavedErrno == errc::no_such_file_or_directory && !exists(path::parent_path(RandomPath))) { StringRef p(RandomPath); SmallString<64> dir_to_create; @@ -440,13 +441,15 @@ rety_open_create: (*i)[1] == '/' && (*i)[2] != '/') return make_error_code(errc::no_such_file_or_directory); - if (::mkdir(dir_to_create.c_str(), 0700) == -1) + if (::mkdir(dir_to_create.c_str(), 0700) == -1 && + errno != errc::file_exists) return error_code(errno, system_category()); } } goto rety_open_create; } - return error_code(errno, system_category()); + + return error_code(SavedErrno, system_category()); } // Make the path absolute. |