Avoid O_CLOEXEC to allow building on older Linux (RHEL5)

Summary:
See https://github.com/google/sanitizers/issues/1253.

Small patch to enable compilation on (ancient) Red Hat Enterprise Linux 5.

Reviewers: kcc, vitalybuka

Reviewed By: vitalybuka

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D80648
This commit is contained in:
Vitaly Buka 2020-05-29 01:02:36 -07:00
parent 7a3a253585
commit 058f5f6fd8
1 changed files with 9 additions and 1 deletions

View File

@ -347,9 +347,17 @@ int GetNamedMappingFd(const char *name, uptr size, int *flags) {
CHECK(internal_strlen(name) < sizeof(shmname) - 10);
internal_snprintf(shmname, sizeof(shmname), "/dev/shm/%zu [%s]",
internal_getpid(), name);
int o_cloexec = 0;
#if defined(O_CLOEXEC)
o_cloexec = O_CLOEXEC;
#endif
int fd = ReserveStandardFds(
internal_open(shmname, O_RDWR | O_CREAT | O_TRUNC | O_CLOEXEC, S_IRWXU));
internal_open(shmname, O_RDWR | O_CREAT | O_TRUNC | o_cloexec, S_IRWXU));
CHECK_GE(fd, 0);
if (!o_cloexec) {
int res = fcntl(fd, F_SETFD, FD_CLOEXEC);
CHECK_EQ(0, res);
}
int res = internal_ftruncate(fd, size);
CHECK_EQ(0, res);
res = internal_unlink(shmname);