+static int do_cmd_get_subbuffer(const char *recvbuf, int sock)
+{
+ int retval = 0, found = 0;;
+ int i, ch_cpu, result;
+ long consumed_old = 0;
+ struct ust_trace *trace;
+ char trace_name[] = "auto";
+ char *channel_and_cpu;
+ char *ch_name;
+
+ DBG("get_subbuf");
+
+ 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;
+ }
+
+ ltt_lock_traces();
+ trace = _ltt_trace_find(trace_name);
+
+ if(trace == NULL) {
+ int result;
+
+ DBG("Cannot find trace. It was likely destroyed by the user.");
+ result = ustcomm_send_reply("NOTFOUND", sock);
+ if(result) {
+ ERR("ustcomm_send_reply failed");
+ retval = -1;
+ goto unlock_traces;
+ }
+
+ goto unlock_traces;
+ }
+
+ for(i=0; i<trace->nr_channels; i++) {
+ struct ust_channel *channel = &trace->channels[i];
+
+ if(!strcmp(trace->channels[i].channel_name, ch_name)) {
+ struct ust_buffer *buf = channel->buf[ch_cpu];
+ char *reply;
+
+ found = 1;
+
+ result = ust_buffers_get_subbuf(buf, &consumed_old);
+ if(result == -EAGAIN) {
+ WARN("missed buffer?");
+ retval = 0;
+
+ goto unlock_traces;
+ } else if (result < 0) {
+ ERR("ust_buffers_get_subbuf: error: %s", strerror(-result));
+ retval = -1;
+
+ goto unlock_traces;
+ }
+ if (asprintf(&reply, "%s %ld", "OK", consumed_old) < 0) {
+ ERR("do_cmd_get_subbuffer: asprintf failed (OK %ld)",
+ consumed_old);
+ retval = -1;
+
+ goto unlock_traces;
+ }
+ result = ustcomm_send_reply(reply, sock);
+ if (result < 0) {
+ ERR("ustcomm_send_reply failed");
+ free(reply);
+ retval = -1;
+
+ goto unlock_traces;
+ }
+ free(reply);
+
+ break;
+ }
+ }
+ if(found == 0) {
+ result = ustcomm_send_reply("NOTFOUND", sock);
+ if (result <= 0) {
+ ERR("ustcomm_send_reply failed");
+ retval = -1;
+
+ goto unlock_traces;
+ }
+ ERR("unable to find channel");
+ }
+
+ unlock_traces:
+ ltt_unlock_traces();
+
+ free_short_chan_name:
+ free(ch_name);
+
+ end:
+ return retval;
+}
+
+
+static int do_cmd_get_buffer_fd(const char *recvbuf, int sock)