From 2ddb81a86943f0ca84b92ae4a1cf144098a9d8bd Mon Sep 17 00:00:00 2001 From: Pierre-Marc Fournier Date: Thu, 18 Feb 2010 10:02:04 -0500 Subject: [PATCH] add NOTFOUND reply for get_subbuf and put_subbuf commands --- libust/tracectl.c | 41 +++++++++++++++++++++++++++++++---------- ustd/ustd.c | 8 ++++++++ 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/libust/tracectl.c b/libust/tracectl.c index 3a5a338..4447b92 100644 --- a/libust/tracectl.c +++ b/libust/tracectl.c @@ -539,8 +539,20 @@ static int do_cmd_get_subbuffer(const char *recvbuf, struct ustcomm_source *src) ltt_unlock_traces(); if(trace == NULL) { - ERR("cannot find trace!"); - retval = -1; + 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); + if(result) { + ERR("ustcomm_send_reply failed"); + free(reply); + retval = -1; + goto free_short_chan_name; + } + + free(reply); goto free_short_chan_name; } @@ -594,6 +606,7 @@ static int do_cmd_put_subbuffer(const char *recvbuf, struct ustcomm_source *src) long consumed_old; char *consumed_old_str; char *endptr; + char *reply = NULL; DBG("put_subbuf"); @@ -629,8 +642,17 @@ static int do_cmd_put_subbuffer(const char *recvbuf, struct ustcomm_source *src) ltt_unlock_traces(); if(trace == NULL) { - ERR("cannot find trace!"); - retval = -1; + WARN("Cannot find trace. It was likely destroyed by the user."); + asprintf(&reply, "%s", "NOTFOUND"); + result = ustcomm_send_reply(&ustcomm_app.server, reply, src); + if(result) { + ERR("ustcomm_send_reply failed"); + free(reply); + retval = -1; + goto free_short_chan_name; + } + + free(reply); goto free_short_chan_name; } @@ -639,7 +661,6 @@ static int do_cmd_put_subbuffer(const char *recvbuf, struct ustcomm_source *src) if(!strcmp(trace->channels[i].channel_name, ch_name)) { struct ust_buffer *buf = channel->buf[ch_cpu]; - char *reply; found = 1; @@ -666,15 +687,15 @@ static int do_cmd_put_subbuffer(const char *recvbuf, struct ustcomm_source *src) } } if(found == 0) { - ERR("get_subbuf_size: unable to find channel"); + ERR("unable to find channel"); } - free_channel_and_cpu: - free(channel_and_cpu); - free_consumed_old_str: - free(consumed_old_str); free_short_chan_name: free(ch_name); + free_consumed_old_str: + free(consumed_old_str); + free_channel_and_cpu: + free(channel_and_cpu); end: return retval; diff --git a/ustd/ustd.c b/ustd/ustd.c index b38593b..7882e34 100644 --- a/ustd/ustd.c +++ b/ustd/ustd.c @@ -160,6 +160,14 @@ int put_subbuffer(struct buffer_info *buf) DBG("subbuffer put %s", buf->name); retval = PUT_SUBBUF_OK; } + else if(!strcmp(received_msg, "NOTFOUND")) { + WARN("For buffer %s, the trace was not found. This likely means it was destroyed by the user.", buf->name); + /* However, maybe this was not the last subbuffer. So + * we return the program died. + */ + retval = PUT_SUBBUF_DIED; + goto end_rep; + } else { DBG("put_subbuffer: received error, we were pushed"); retval = PUT_SUBBUF_PUSHED; -- 2.34.1