Large cleanup, mostly removal of all printk's and printfs in libust
[ust.git] / libust / tracectl.c
index 873b0f66b432e150853363fb1456f5c0b3e7fc55..584a94cff8067e36626bd537bb7ac1d48731ee25 100644 (file)
@@ -30,6 +30,7 @@
 #include <urcu-bp.h>
 
 #include <ust/marker.h>
+#include <ust/tracectl.h>
 #include "tracer.h"
 #include "usterr.h"
 #include "ustcomm.h"
@@ -692,7 +693,6 @@ void *listener_main(void *p)
                                WARN("invalid marker name");
                                goto next_cmd;
                        }
-                       printf("%s %s\n", channel_name, marker_name);
 
                        result = ltt_marker_connect(channel_name, marker_name, "default");
                        if(result < 0) {
@@ -708,7 +708,6 @@ void *listener_main(void *p)
 
                        if(marker_name == NULL) {
                        }
-                       printf("%s %s\n", channel_name, marker_name);
 
                        result = ltt_marker_disconnect(channel_name, marker_name, "default");
                        if(result < 0) {
@@ -949,7 +948,24 @@ static void __attribute__((constructor)) init()
                /* Ensure markers are initialized */
                init_markers();
 
-               /* In case. */
+               /* FIXME: When starting early tracing (here), depending on the
+                * order of constructors, it is very well possible some marker
+                * sections are not yet registered. Because of this, some
+                * channels may not be registered. Yet, we are about to ask the
+                * daemon to collect the channels. Channels which are not yet
+                * registered will not be collected.
+                *
+                * Currently, in LTTng, there is no way to add a channel after
+                * trace start. The reason for this is that it induces complex
+                * concurrency issues on the trace structures, which can only
+                * be resolved using RCU. This has not been done yet. As a
+                * workaround, we are forcing the registration of the "ust"
+                * channel here. This is the only channel (apart from metadata)
+                * that can be reliably used in early tracing.
+                *
+                * Non-early tracing does not have this problem and can use
+                * arbitrary channel names.
+                */
                ltt_channels_register("ust");
 
                result = ltt_trace_setup(trace_name);
@@ -1105,9 +1121,13 @@ void ust_potential_exec(void)
  * the new process, anytime a process whose memory is not shared with
  * the parent is created. If this function is not called, the events
  * of the new process will not be collected.
+ *
+ * Signals should be disabled before the fork and reenabled only after
+ * this call in order to guarantee tracing is not started before ust_fork()
+ * sanitizes the new process.
  */
 
-void ust_fork(void)
+static void ust_fork(void)
 {
        struct blocked_consumer *bc;
        struct blocked_consumer *deletable_bc = NULL;
@@ -1143,3 +1163,55 @@ void ust_fork(void)
        inform_consumer_daemon("auto");
 }
 
+void ust_before_fork(ust_fork_info_t *fork_info)
+{
+        /* Disable signals. This is to avoid that the child
+         * intervenes before it is properly setup for tracing. It is
+         * safer to disable all signals, because then we know we are not
+         * breaking anything by restoring the original mask.
+         */
+       sigset_t all_sigs;
+       int result;
+
+        /* FIXME:
+                - only do this if tracing is active
+        */
+
+        /* Disable signals */
+        sigfillset(&all_sigs);
+        result = sigprocmask(SIG_BLOCK, &all_sigs, &fork_info->orig_sigs);
+        if(result == -1) {
+                PERROR("sigprocmask");
+                return;
+        }
+}
+
+/* Don't call this function directly in a traced program */
+static void ust_after_fork_common(ust_fork_info_t *fork_info)
+{
+       int result;
+       sigset_t orig_sigs;
+
+        /* Restore signals */
+        result = sigprocmask(SIG_SETMASK, &fork_info->orig_sigs, NULL);
+        if(result == -1) {
+                PERROR("sigprocmask");
+                return;
+        }
+}
+
+void ust_after_fork_parent(ust_fork_info_t *fork_info)
+{
+       /* Reenable signals */
+       ust_after_fork_common(fork_info);
+}
+
+void ust_after_fork_child(ust_fork_info_t *fork_info)
+{
+       /* First sanitize the child */
+       ust_fork();
+
+       /* Then reenable interrupts */
+       ust_after_fork_common(fork_info);
+}
+
This page took 0.024006 seconds and 4 git commands to generate.