X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=libust%2Ftracectl.c;h=dd61ebe7f7521cb2d6e79eff7592584b14a8c883;hb=b17081c0591fd50dda4e8a17d71112e130a7b656;hp=e339218ebd216108fb1f4c7bf6b9cc2e690ec442;hpb=08b8805efffcad4e0f713272cac6f75390176396;p=ust.git diff --git a/libust/tracectl.c b/libust/tracectl.c index e339218..dd61ebe 100644 --- a/libust/tracectl.c +++ b/libust/tracectl.c @@ -35,6 +35,7 @@ #include #include +#include #include #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 @@ -282,12 +298,14 @@ static int do_cmd_get_shmid(const char *recvbuf, struct ustcomm_source *src) channel_and_cpu = nth_token(recvbuf, 1); if(channel_and_cpu == NULL) { ERR("cannot parse channel"); + retval = -1; goto end; } seperate_channel_cpu(channel_and_cpu, &ch_name, &ch_cpu); if(ch_cpu == -1) { ERR("problem parsing channel name"); + retval = -1; goto free_short_chan_name; } @@ -360,12 +378,14 @@ static int do_cmd_get_n_subbufs(const char *recvbuf, struct ustcomm_source *src) channel_and_cpu = nth_token(recvbuf, 1); if(channel_and_cpu == NULL) { ERR("cannot parse channel"); + retval = -1; goto end; } seperate_channel_cpu(channel_and_cpu, &ch_name, &ch_cpu); if(ch_cpu == -1) { ERR("problem parsing channel name"); + retval = -1; goto free_short_chan_name; } @@ -434,12 +454,14 @@ static int do_cmd_get_subbuf_size(const char *recvbuf, struct ustcomm_source *sr channel_and_cpu = nth_token(recvbuf, 1); if(channel_and_cpu == NULL) { ERR("cannot parse channel"); + retval = -1; goto end; } seperate_channel_cpu(channel_and_cpu, &ch_name, &ch_cpu); if(ch_cpu == -1) { ERR("problem parsing channel name"); + retval = -1; goto free_short_chan_name; } @@ -522,6 +544,7 @@ static int do_cmd_set_subbuf_size(const char *recvbuf, struct ustcomm_source *sr if(ch_name == NULL) { ERR("cannot parse channel"); + retval = -1; goto end; } @@ -577,10 +600,12 @@ static int do_cmd_set_subbuf_num(const char *recvbuf, struct ustcomm_source *src if(ch_name == NULL) { ERR("cannot parse channel"); + retval = -1; goto end; } if (num < 2) { ERR("subbuffer count should be greater than 2"); + retval = -1; goto end; } @@ -629,12 +654,14 @@ static int do_cmd_get_subbuffer(const char *recvbuf, struct ustcomm_source *src) channel_and_cpu = nth_token(recvbuf, 1); if(channel_and_cpu == NULL) { ERR("cannot parse channel"); + retval = -1; goto end; } seperate_channel_cpu(channel_and_cpu, &ch_name, &ch_cpu); if(ch_cpu == -1) { ERR("problem parsing channel name"); + retval = -1; goto free_short_chan_name; } @@ -664,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; @@ -856,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) { @@ -1016,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");