From: Josh Stone Date: Tue, 2 Oct 2012 17:55:19 +0000 (-0700) Subject: stapdyn: Use FD_CLOEXEC on _stp_mem_fd instead of O_CLOEXEC X-Git-Tag: release-2.0~50 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=7d8bff7071b839b9c1e9bb5e140ac83281f739ec;p=systemtap.git stapdyn: Use FD_CLOEXEC on _stp_mem_fd instead of O_CLOEXEC 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. --- diff --git a/runtime/dyninst/runtime.h b/runtime/dyninst/runtime.h index 285a4212a..d5c814462 100644 --- a/runtime/dyninst/runtime.h +++ b/runtime/dyninst/runtime.h @@ -160,7 +160,11 @@ __attribute__((constructor)) 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)