X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=ustd%2Fustd.c;h=7882e34544278f4cd68a08303670e8b8d35d75ea;hb=2ddb81a86943f0ca84b92ae4a1cf144098a9d8bd;hp=969c192abdb66bea7b9ce93dd48d7a994b5fe70c;hpb=204141ee9da22a244c9095287f4f1c513784b171;p=ust.git diff --git a/ustd/ustd.c b/ustd/ustd.c index 969c192..7882e34 100644 --- a/ustd/ustd.c +++ b/ustd/ustd.c @@ -48,6 +48,7 @@ #define PUT_SUBBUF_OK 1 #define PUT_SUBBUF_DIED 0 #define PUT_SUBBUF_PUSHED 2 +#define PUT_SUBBUF_DONE 3 char *sock_path=NULL; char *trace_path=NULL; @@ -98,6 +99,11 @@ int get_subbuffer(struct buffer_info *buf) retval = GET_SUBBUF_DONE; goto end_rep; } + 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); + retval = GET_SUBBUF_DONE; + goto end_rep; + } else { DBG("error getting subbuffer %s", buf->name); retval = -1; @@ -130,11 +136,18 @@ int put_subbuffer(struct buffer_info *buf) retval = PUT_SUBBUF_DIED; goto end; } - if(result < 0) { + else if(result < 0) { ERR("put_subbuffer: send_message failed"); retval = -1; goto end; } + else if(result == 0) { + /* Program seems finished. However this might not be + * the last subbuffer that has to be collected. + */ + retval = PUT_SUBBUF_DIED; + goto end; + } result = sscanf(received_msg, "%as", &rep_code); if(result != 1) { @@ -147,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; @@ -359,6 +380,24 @@ struct buffer_info *connect_buffer(pid_t pid, const char *bufname) return buf; } +int write_current_subbuffer(struct buffer_info *buf) +{ + int result; + + void *subbuf_mem = buf->mem + (buf->consumed_old & (buf->n_subbufs * buf->subbuf_size-1)); + + size_t cur_sb_size = subbuffer_data_size(subbuf_mem); + + result = patient_write(buf->file_fd, subbuf_mem, cur_sb_size); + if(result == -1) { + PERROR("write"); + /* FIXME: maybe drop this trace */ + return 0; + } + + return 0; +} + int consumer_loop(struct buffer_info *buf) { int result; @@ -382,11 +421,8 @@ int consumer_loop(struct buffer_info *buf) } /* write data to file */ - result = patient_write(buf->file_fd, buf->mem + (buf->consumed_old & (buf->n_subbufs * buf->subbuf_size-1)), buf->subbuf_size); - if(result == -1) { - PERROR("write"); - /* FIXME: maybe drop this trace */ - } + write_current_subbuffer(buf); + /* FIXME: handle return value? */ /* put the subbuffer */ /* FIXME: we actually should unput the buffer before consuming... */ @@ -405,6 +441,15 @@ int consumer_loop(struct buffer_info *buf) finish_consuming_dead_subbuffer(buf); break; } + else if(result == PUT_SUBBUF_DONE) { + /* Done with this subbuffer */ + /* FIXME: add a case where this branch is used? Upon + * normal trace termination, at put_subbuf time, a + * special last-subbuffer code could be returned by + * the listener. + */ + break; + } else if(result == PUT_SUBBUF_OK) { } }