take ltt_trace_lock during the full manipulation of the data struct
authorPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Thu, 25 Feb 2010 22:53:39 +0000 (17:53 -0500)
committerPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Fri, 26 Feb 2010 05:32:29 +0000 (00:32 -0500)
libust/tracectl.c

index d4cb3efbcb7a97b5963106143b37640090b38822..d517fe042ad706e9ade94f9d7620f3f310bf85b5 100644 (file)
@@ -552,7 +552,6 @@ static int do_cmd_set_subbuf_size(const char *recvbuf, struct ustcomm_source *sr
        trace = _ltt_trace_find_setup(trace_name);
        if(trace == NULL) {
                ERR("cannot find trace!");
-               ltt_unlock_traces();
                retval = -1;
                goto end;
        }
@@ -573,9 +572,8 @@ static int do_cmd_set_subbuf_size(const char *recvbuf, struct ustcomm_source *sr
                ERR("unable to find channel");
        }
 
-       ltt_unlock_traces();
-
        end:
+       ltt_unlock_traces();
        return retval;
 }
 
@@ -608,7 +606,6 @@ static int do_cmd_set_subbuf_num(const char *recvbuf, struct ustcomm_source *src
        trace = _ltt_trace_find_setup(trace_name);
        if(trace == NULL) {
                ERR("cannot find trace!");
-               ltt_unlock_traces();
                retval = -1;
                goto end;
        }
@@ -629,9 +626,8 @@ static int do_cmd_set_subbuf_num(const char *recvbuf, struct ustcomm_source *src
                ERR("unable to find channel");
        }
 
-       ltt_unlock_traces();
-
        end:
+       ltt_unlock_traces();
        return retval;
 }
 
@@ -662,24 +658,19 @@ static int do_cmd_get_subbuffer(const char *recvbuf, struct ustcomm_source *src)
 
        ltt_lock_traces();
        trace = _ltt_trace_find(trace_name);
-       ltt_unlock_traces();
 
        if(trace == NULL) {
-               char *reply;
                int result;
 
                WARN("Cannot find trace. It was likely destroyed by the user.");
-               asprintf(&reply, "%s", "NOTFOUND");
-               result = ustcomm_send_reply(&ustcomm_app.server, reply, src);
+               result = ustcomm_send_reply(&ustcomm_app.server, "NOTFOUND", src);
                if(result) {
                        ERR("ustcomm_send_reply failed");
-                       free(reply);
                        retval = -1;
-                       goto free_short_chan_name;
+                       goto unlock_traces;
                }
 
-               free(reply);
-               goto free_short_chan_name;
+               goto unlock_traces;
        }
 
        for(i=0; i<trace->nr_channels; i++) {
@@ -694,7 +685,7 @@ static int do_cmd_get_subbuffer(const char *recvbuf, struct ustcomm_source *src)
                        bc = (struct blocked_consumer *) malloc(sizeof(struct blocked_consumer));
                        if(bc == NULL) {
                                ERR("malloc returned NULL");
-                               goto free_short_chan_name;
+                               goto unlock_traces;
                        }
                        bc->fd_consumer = src->fd;
                        bc->fd_producer = buf->data_ready_fd_read;
@@ -711,6 +702,9 @@ static int do_cmd_get_subbuffer(const char *recvbuf, struct ustcomm_source *src)
                ERR("unable to find channel");
        }
 
+       unlock_traces:
+       ltt_unlock_traces();
+
        free_short_chan_name:
        free(ch_name);
 
@@ -765,21 +759,17 @@ static int do_cmd_put_subbuffer(const char *recvbuf, struct ustcomm_source *src)
 
        ltt_lock_traces();
        trace = _ltt_trace_find(trace_name);
-       ltt_unlock_traces();
 
        if(trace == NULL) {
                WARN("Cannot find trace. It was likely destroyed by the user.");
-               asprintf(&reply, "%s", "NOTFOUND");
-               result = ustcomm_send_reply(&ustcomm_app.server, reply, src);
+               result = ustcomm_send_reply(&ustcomm_app.server, "NOTFOUND", src);
                if(result) {
                        ERR("ustcomm_send_reply failed");
-                       free(reply);
                        retval = -1;
-                       goto free_short_chan_name;
+                       goto unlock_traces;
                }
 
-               free(reply);
-               goto free_short_chan_name;
+               goto unlock_traces;
        }
 
        for(i=0; i<trace->nr_channels; i++) {
@@ -805,7 +795,7 @@ static int do_cmd_put_subbuffer(const char *recvbuf, struct ustcomm_source *src)
                                ERR("ustcomm_send_reply failed");
                                free(reply);
                                retval = -1;
-                               goto free_channel_and_cpu;
+                               goto unlock_traces;
                        }
 
                        free(reply);
@@ -816,6 +806,8 @@ static int do_cmd_put_subbuffer(const char *recvbuf, struct ustcomm_source *src)
                ERR("unable to find channel");
        }
 
+       unlock_traces:
+       ltt_unlock_traces();
        free_short_chan_name:
        free(ch_name);
        free_consumed_old_str:
This page took 0.028349 seconds and 4 git commands to generate.