null check for disable_marker
[ust.git] / libust / tracectl.c
index 8d57b8fe9324be657629fd3994668437fc86d1dd..dd61ebe7f7521cb2d6e79eff7592584b14a8c883 100644 (file)
@@ -35,6 +35,7 @@
 #include <urcu/uatomic_arch.h>
 
 #include <ust/marker.h>
+#include <ust/tracepoint.h>
 #include <ust/tracectl.h>
 #include "tracer.h"
 #include "usterr.h"
@@ -127,6 +128,21 @@ static void print_markers(FILE *fp)
        unlock_markers();
 }
 
+static void print_trace_events(FILE *fp)
+{
+       struct trace_event_iter iter;
+
+       lock_trace_events();
+       trace_event_iter_reset(&iter);
+       trace_event_iter_start(&iter);
+
+       while(iter.trace_event) {
+               fprintf(fp, "trace_event: %s\n", iter.trace_event->name);
+               trace_event_iter_next(&iter);
+       }
+       unlock_trace_events();
+}
+
 static int init_socket(void);
 
 /* Ask the daemon to collect a trace called trace_name and being
@@ -675,9 +691,9 @@ static int do_cmd_get_subbuffer(const char *recvbuf, struct ustcomm_source *src)
 
                        found = 1;
 
-                       bc = (struct blocked_consumer *) malloc(sizeof(struct blocked_consumer));
+                       bc = (struct blocked_consumer *) zmalloc(sizeof(struct blocked_consumer));
                        if(bc == NULL) {
-                               ERR("malloc returned NULL");
+                               ERR("zmalloc returned NULL");
                                goto unlock_traces;
                        }
                        bc->fd_consumer = src->fd;
@@ -867,8 +883,29 @@ int process_client_cmd(char *recvbuf, struct ustcomm_source *src)
                result = ustcomm_send_reply(&ustcomm_app.server, ptr, src);
 
                free(ptr);
-       }
-       else if(!strcmp(recvbuf, "start")) {
+       } else if (!strcmp(recvbuf, "print_trace_events")) {
+               print_trace_events(stderr);
+
+       } else if(!strcmp(recvbuf, "list_trace_events")) {
+               char *ptr;
+               size_t size;
+               FILE *fp;
+
+               fp = open_memstream(&ptr, &size);
+               if (fp == NULL) {
+                       ERR("opening memstream failed");
+                       return -1;
+               }
+               print_trace_events(fp);
+               fclose(fp);
+
+               result = ustcomm_send_reply(&ustcomm_app.server, ptr, src);
+               if (result < 0) {
+                       ERR("list_trace_events failed");
+                       return -1;
+               }
+               free(ptr);
+       } else if(!strcmp(recvbuf, "start")) {
                /* start is an operation that setups the trace, allocates it and starts it */
                result = ltt_trace_setup(trace_name);
                if(result < 0) {
@@ -1027,7 +1064,9 @@ int process_client_cmd(char *recvbuf, struct ustcomm_source *src)
 
                result = sscanf(channel_slash_name, "%a[^/]/%as", &channel_name, &marker_name);
 
-               if(marker_name == NULL) {
+               if(channel_name == NULL || marker_name == NULL) {
+                       WARN("invalid marker name");
+                       goto next_cmd;
                }
 
                result = ltt_marker_disconnect(channel_name, marker_name, "default");
This page took 0.030592 seconds and 4 git commands to generate.