[ltt-dev] [UST PATCH] Make tracectl destructor aware of fork status
Nils Carlson
nils.carlson at ericsson.com
Mon Oct 25 06:59:47 EDT 2010
This little patch checks to see whether we have used a fork
wrapper to fork. If not we won't have a working UST in the process
and can skip the destructor stage.
Signed-off-by: Nils Carlson <nils.carlson at ericsson.com>
---
libust/tracectl.c | 14 ++++++++++++++
1 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/libust/tracectl.c b/libust/tracectl.c
index 3d09cc2..5f942cd 100644
--- a/libust/tracectl.c
+++ b/libust/tracectl.c
@@ -50,6 +50,12 @@
*/
s64 pidunique = -1LL;
+/* The process pid is used to detect a non-traceable fork
+ * and allow the non-traceable fork to be ignored
+ * by destructor sequences in libust
+ */
+static pid_t processpid = 0;
+
static struct ustcomm_header _receive_header;
static struct ustcomm_header *receive_header = &_receive_header;
static char receive_buffer[USTCOMM_BUFFER_SIZE];
@@ -1201,6 +1207,7 @@ static void __attribute__((constructor)) init()
* pid, (before and after an exec).
*/
pidunique = make_pidunique();
+ processpid = getpid();
DBG("Tracectl constructor");
@@ -1466,6 +1473,10 @@ static void stop_listener(void)
static void __attribute__((destructor)) keepalive()
{
+ if (processpid != getpid()) {
+ return;
+ }
+
if (trace_recording() && LOAD_SHARED(buffers_to_export)) {
int total = 0;
DBG("Keeping process alive for consumer daemon...");
@@ -1516,6 +1527,9 @@ static void ust_fork(void)
/* FIXME: technically, the locks could have been taken before the fork */
DBG("ust: forking");
+ /* Get the pid of the new process */
+ processpid = getpid();
+
/* break lock if necessary */
ltt_unlock_traces();
--
1.7.1
More information about the lttng-dev
mailing list