[libcxx-commits] [PATCH] D130214: [libc++][test] Fix infinite loop when mkstemp fails
Ryan Prichard via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Jul 20 17:34:51 PDT 2022
rprichard created this revision.
rprichard added reviewers: jroelofs, danalbert.
Herald added a project: All.
rprichard requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.
mkstemp is guaranteed to make at least TMP_MAX attempts to create the
random file, and if it can't, it fails with EEXIST. get_temp_file_name
shouldn't call mkstemp again if it fails with anything other than
EEXIST. A single mkstemp call seems sufficient.
On Android, I've seen mkstemp fail with:
- EROFS (because cwd wasn't set to a writable filesystem)
- EACCES (because cwd pointed to a dir owned by root, but the test program was running as the shell user instead)
Previously, get_temp_file_name would run forever in these situations.
See D4962 <https://reviews.llvm.org/D4962> and "llvm-svn: 229035"
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D130214
Files:
libcxx/test/support/platform_support.h
Index: libcxx/test/support/platform_support.h
===================================================================
--- libcxx/test/support/platform_support.h
+++ libcxx/test/support/platform_support.h
@@ -75,16 +75,12 @@
abort();
}
#else
- std::string Name;
- int FD = -1;
- do {
- Name = "libcxx.XXXXXX";
- FD = mkstemp(&Name[0]);
- if (FD == -1 && errno == EINVAL) {
- perror("mkstemp");
- abort();
- }
- } while (FD == -1);
+ std::string Name = "libcxx.XXXXXX";
+ int FD = mkstemp(&Name[0]);
+ if (FD == -1) {
+ perror("mkstemp");
+ abort();
+ }
close(FD);
return Name;
#endif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130214.446309.patch
Type: text/x-patch
Size: 693 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220721/a44a14af/attachment-0001.bin>
More information about the libcxx-commits
mailing list