O_CLOEXEC is only available since Linux 2.6.23, which is fairly old, but
we may still care to run on such systems. Using fcntl FD_CLOEXEC can
accomplish the same thing, and we don't need to worry about the race of
other threads calling exec at the same time as our module load, because
the whole process will be frozen.
static void stp_dyninst_ctor(void)
{
stap_hash_seed = _stp_random_u ((unsigned long)-1);
- _stp_mem_fd = open("/proc/self/mem", O_RDWR | O_CLOEXEC /*| O_LARGEFILE*/);
+
+ _stp_mem_fd = open("/proc/self/mem", O_RDWR /*| O_LARGEFILE*/);
+ if (_stp_mem_fd != -1) {
+ fcntl(_stp_mem_fd, F_SETFD, FD_CLOEXEC);
+ }
}
int stp_dyninst_session_init(void)