OSDN Git Service

Avoid O_CLOEXEC to allow building on older Linux (RHEL5)
authorVitaly Buka <vitalybuka@google.com>
Fri, 29 May 2020 08:02:36 +0000 (01:02 -0700)
committerVitaly Buka <vitalybuka@google.com>
Fri, 29 May 2020 09:06:53 +0000 (02:06 -0700)
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

compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp

index d890a3a..e21661b 100644 (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);