+ 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)
+{
+ int retval = 0;
+ struct ust_trace *trace;
+ char trace_name[] = "auto";
+ int i;
+ char *channel_and_cpu;
+ int found = 0;
+ char *ch_name;
+ int ch_cpu;
+ struct ustcomm_header header;
+
+ DBG("get_buffer_fd");
+
+ 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];