aboutsummaryrefslogtreecommitdiffstats
path: root/src/prof.c
diff options
context:
space:
mode:
authorY. T. Chung <zonyitoo@gmail.com>2017-07-20 23:02:23 +0800
committerDavid Goldblatt <davidtgoldblatt@gmail.com>2017-07-20 14:13:33 -0700
commit0975b88dfd3a890f469c8c282a5140013af85ab2 (patch)
tree147ac0ea173848299cba7ed803961726f400263e /src/prof.c
parentfb6787a78c3a1e3a4868520d0531fc2ebdda21d8 (diff)
downloadplatform_external_jemalloc_new-0975b88dfd3a890f469c8c282a5140013af85ab2.tar.gz
platform_external_jemalloc_new-0975b88dfd3a890f469c8c282a5140013af85ab2.tar.bz2
platform_external_jemalloc_new-0975b88dfd3a890f469c8c282a5140013af85ab2.zip
Fall back to FD_CLOEXEC when O_CLOEXEC is unavailable.
Older Linux systems don't have O_CLOEXEC. If that's the case, we fcntl immediately after open, to minimize the length of the racy period in which an operation in another thread can leak a file descriptor to a child.
Diffstat (limited to 'src/prof.c')
-rw-r--r--src/prof.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/prof.c b/src/prof.c
index 975722c4..a1ca9e2c 100644
--- a/src/prof.c
+++ b/src/prof.c
@@ -1409,7 +1409,13 @@ prof_open_maps(const char *format, ...) {
va_start(ap, format);
malloc_vsnprintf(filename, sizeof(filename), format, ap);
va_end(ap);
+
+#if defined(O_CLOEXEC)
mfd = open(filename, O_RDONLY | O_CLOEXEC);
+#else
+ mfd = open(filename, O_RDONLY);
+ fcntl(mfd, F_SETFD, fcntl(mfd, F_GETFD) | FD_CLOEXEC);
+#endif
return mfd;
}