Skip to content

Commit 058f5f6

Browse files
committed
Avoid O_CLOEXEC to allow building on older Linux (RHEL5)
Summary: See google/sanitizers#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
1 parent 7a3a253 commit 058f5f6

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,17 @@ int GetNamedMappingFd(const char *name, uptr size, int *flags) {
347347
CHECK(internal_strlen(name) < sizeof(shmname) - 10);
348348
internal_snprintf(shmname, sizeof(shmname), "/dev/shm/%zu [%s]",
349349
internal_getpid(), name);
350+
int o_cloexec = 0;
351+
#if defined(O_CLOEXEC)
352+
o_cloexec = O_CLOEXEC;
353+
#endif
350354
int fd = ReserveStandardFds(
351-
internal_open(shmname, O_RDWR | O_CREAT | O_TRUNC | O_CLOEXEC, S_IRWXU));
355+
internal_open(shmname, O_RDWR | O_CREAT | O_TRUNC | o_cloexec, S_IRWXU));
352356
CHECK_GE(fd, 0);
357+
if (!o_cloexec) {
358+
int res = fcntl(fd, F_SETFD, FD_CLOEXEC);
359+
CHECK_EQ(0, res);
360+
}
353361
int res = internal_ftruncate(fd, size);
354362
CHECK_EQ(0, res);
355363
res = internal_unlink(shmname);

0 commit comments

Comments
 (0)