[llvm] r176226 - [PathV2] In llvm::sys::fs::unique_file, make sure it doesn't fall into an infinite loop by constantly trying
Argyrios Kyrtzidis
akyrtzi at gmail.com
Wed Feb 27 18:18:36 PST 2013
On Feb 27, 2013, at 4:42 PM, Aaron Ballman <aaron at aaronballman.com> wrote:
> Can we fall into the same trap in the Windows version of this code too?
I don't have a windows machine to test.
For anyone interested, the way I tested the fix was like this:
$ mkdir temp
$ cd temp
$ touch empty.c
$ lldb -- /path/to/clang -cc1 empty.c -emit-pch -o empty.pch
(stop at the "rety_open_create:" label of unique_file function)
Now delete 'temp' directory and make sure the function does not get stuck.
-Argyrios
>
> ~Aaron
>
> On Wed, Feb 27, 2013 at 7:38 PM, Argyrios Kyrtzidis <akyrtzi at gmail.com> wrote:
>> Author: akirtzidis
>> Date: Wed Feb 27 18:38:19 2013
>> New Revision: 176226
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=176226&view=rev
>> Log:
>> [PathV2] In llvm::sys::fs::unique_file, make sure it doesn't fall into an infinite loop by constantly trying
>> to create the parent path.
>>
>> This can happen if the path is a relative filename and the current directory was removed.
>> Thanks to Daniel D. for the hint in fixing it.
>>
>> Modified:
>> llvm/trunk/lib/Support/Unix/PathV2.inc
>>
>> Modified: llvm/trunk/lib/Support/Unix/PathV2.inc
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/PathV2.inc?rev=176226&r1=176225&r2=176226&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/Support/Unix/PathV2.inc (original)
>> +++ llvm/trunk/lib/Support/Unix/PathV2.inc Wed Feb 27 18:38:19 2013
>> @@ -417,6 +417,10 @@ retry_random_path:
>> RandomPath[i] = "0123456789abcdef"[sys::Process::GetRandomNumber() & 15];
>> }
>>
>> + // Make sure we don't fall into an infinite loop by constantly trying
>> + // to create the parent path.
>> + bool TriedToCreateParent = false;
>> +
>> // Try to open + create the file.
>> rety_open_create:
>> int RandomFD = ::open(RandomPath.c_str(), O_RDWR | O_CREAT | O_EXCL, mode);
>> @@ -427,7 +431,9 @@ rety_open_create:
>> goto retry_random_path;
>> // If path prefix doesn't exist, try to create it.
>> if (SavedErrno == errc::no_such_file_or_directory &&
>> - !exists(path::parent_path(RandomPath))) {
>> + !exists(path::parent_path(RandomPath)) &&
>> + !TriedToCreateParent) {
>> + TriedToCreateParent = true;
>> StringRef p(RandomPath);
>> SmallString<64> dir_to_create;
>> for (path::const_iterator i = path::begin(p),
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130227/65834c41/attachment.html>
More information about the llvm-commits
mailing list