]> sourceware.org Git - systemtap.git/commitdiff
stapdyn: Use FD_CLOEXEC on _stp_mem_fd instead of O_CLOEXEC
authorJosh Stone <jistone@redhat.com>
Tue, 2 Oct 2012 17:55:19 +0000 (10:55 -0700)
committerJosh Stone <jistone@redhat.com>
Tue, 2 Oct 2012 18:41:41 +0000 (11:41 -0700)
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.

runtime/dyninst/runtime.h

index 285a4212a25c70b6be18724db65685d0f9617bf6..d5c81446222f0dd5a6f58cf80b1e8689e05b13df 100644 (file)
@@ -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)
This page took 0.027748 seconds and 5 git commands to generate.