Make tracectl destructor aware of fork status
authorNils Carlson <nils.carlson@ericsson.com>
Mon, 25 Oct 2010 10:57:30 +0000 (12:57 +0200)
committerNils Carlson <nils.carlson@ericsson.com>
Tue, 26 Oct 2010 16:35:28 +0000 (18:35 +0200)
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@ericsson.com>
Acked-by: David Goulet <david.goulet@polymtl.ca>
libust/tracectl.c

index 3d09cc2a136ea5e49e48ba19d6d1c40b443a79cb..5f942cd8306a3cdb661c73bb45484782bb6a245d 100644 (file)
  */
 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();
 
This page took 0.024952 seconds and 4 git commands to generate.