X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fplugins%2Fctf%2Flttng-live%2Fviewer-connection.c;h=d6d2851ab932d6c14a8b8667486ac06e7519fdee;hb=0e73b4c29c6467ece0fc1955a98408b7f4b3de91;hp=2cf23d171ce8ec326654af8d3400fc6f97a0c96c;hpb=ecb4ba8aa48c8d0deab589b7c1f4c999a52aa355;p=babeltrace.git diff --git a/src/plugins/ctf/lttng-live/viewer-connection.c b/src/plugins/ctf/lttng-live/viewer-connection.c index 2cf23d17..d6d2851a 100644 --- a/src/plugins/ctf/lttng-live/viewer-connection.c +++ b/src/plugins/ctf/lttng-live/viewer-connection.c @@ -110,6 +110,24 @@ enum ctf_msg_iter_medium_status viewer_status_to_ctf_msg_iter_medium_status( } } +static inline +void viewer_connection_close_socket( + struct live_viewer_connection *viewer_connection) +{ + bt_self_component_class *self_comp_class = + viewer_connection->self_comp_class; + bt_self_component *self_comp = + viewer_connection->self_comp; + int ret = bt_socket_close(viewer_connection->control_sock); + if (ret == -1) { + BT_COMP_OR_COMP_CLASS_LOGW_ERRNO( + self_comp, self_comp_class, + "Error closing viewer connection socket: ", "."); + } + + viewer_connection->control_sock = BT_INVALID_SOCKET; +} + /* * This function receives a message from the Relay daemon. * If it received the entire message, it returns _OK, @@ -157,12 +175,14 @@ enum lttng_live_viewer_status lttng_live_recv( } } else { /* - * For any other types of socket error, returng - * an error. + * For any other types of socket error, close + * the socket and return an error. */ LTTNG_LIVE_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE_ERRNO( self_comp, self_comp_class, "Error receiving from Relay", "."); + + viewer_connection_close_socket(viewer_connection); status = LTTNG_LIVE_VIEWER_STATUS_ERROR; goto end; } @@ -172,10 +192,12 @@ enum lttng_live_viewer_status lttng_live_recv( * connection was orderly shutdown from the other peer. * If that happens when we are trying to receive * a message from it, it means something when wrong. + * Close the socket and return an error. */ - status = LTTNG_LIVE_VIEWER_STATUS_ERROR; BT_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE(self_comp, self_comp_class, "Remote side has closed connection"); + viewer_connection_close_socket(viewer_connection); + status = LTTNG_LIVE_VIEWER_STATUS_ERROR; goto end; } @@ -236,11 +258,14 @@ enum lttng_live_viewer_status lttng_live_send( } } else { /* - * The send() call returned an error. + * For any other types of socket error, close + * the socket and return an error. */ LTTNG_LIVE_COMP_OR_COMP_CLASS_LOGE_APPEND_CAUSE_ERRNO( self_comp, self_comp_class, "Error sending to Relay", "."); + + viewer_connection_close_socket(viewer_connection); status = LTTNG_LIVE_VIEWER_STATUS_ERROR; goto end; } @@ -1150,7 +1175,12 @@ enum lttng_live_viewer_status lttng_live_detach_session( const size_t cmd_buf_len = sizeof(cmd) + sizeof(rq); char cmd_buf[cmd_buf_len]; - if (!session->attached) { + /* + * The session might already be detached and the viewer socket might + * already been closed. This happens when calling this function when + * tearing down the graph after an error. + */ + if (!session->attached || viewer_connection->control_sock == BT_INVALID_SOCKET) { return 0; } @@ -1218,7 +1248,7 @@ enum lttng_live_get_one_metadata_status lttng_live_get_one_metadata_packet( struct lttng_viewer_get_metadata rq; struct lttng_viewer_metadata_packet rp; char *data = NULL; - ssize_t ret_len; + ssize_t writelen; struct lttng_live_session *session = trace->session; struct lttng_live_msg_iter *lttng_live_msg_iter = session->lttng_live_msg_iter; @@ -1313,16 +1343,14 @@ enum lttng_live_get_one_metadata_status lttng_live_get_one_metadata_packet( /* * Write the metadata to the file handle. */ - do { - ret_len = fwrite(data, 1, len, fp); - } while (ret_len < 0 && errno == EINTR); - if (ret_len < 0) { + writelen = fwrite(data, sizeof(uint8_t), len, fp); + if (writelen != len) { BT_COMP_LOGE_APPEND_CAUSE(self_comp, "Writing in the metadata file stream"); status = LTTNG_LIVE_GET_ONE_METADATA_STATUS_ERROR; goto error; } - BT_ASSERT(ret_len == len); + *reply_len = len; status = LTTNG_LIVE_GET_ONE_METADATA_STATUS_OK; @@ -1443,7 +1471,7 @@ enum lttng_live_iterator_status lttng_live_get_next_index( if (flags & LTTNG_VIEWER_FLAG_NEW_METADATA) { BT_COMP_LOGD("Received get_next_index response: new metadata needed"); - trace->new_metadata_needed = true; + trace->metadata_stream_state = LTTNG_LIVE_METADATA_STREAM_STATE_NEEDED; } if (flags & LTTNG_VIEWER_FLAG_NEW_STREAM) { BT_COMP_LOGD("Received get_next_index response: new streams needed"); @@ -1556,7 +1584,7 @@ enum ctf_msg_iter_medium_status lttng_live_get_stream_bytes( case LTTNG_VIEWER_GET_PACKET_ERR: if (flags & LTTNG_VIEWER_FLAG_NEW_METADATA) { BT_COMP_LOGD("get_data_packet: new metadata needed, try again later"); - trace->new_metadata_needed = true; + trace->metadata_stream_state = LTTNG_LIVE_METADATA_STREAM_STATE_NEEDED; } if (flags & LTTNG_VIEWER_FLAG_NEW_STREAM) { BT_COMP_LOGD("get_data_packet: new streams needed, try again later");