mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-07-01 03:29:11 +03:00
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.
This commit is contained in:
parent
fb6787a78c
commit
0975b88dfd
2 changed files with 28 additions and 5 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue