From: David Goulet Date: Wed, 19 Dec 2012 23:25:49 +0000 (-0500) Subject: Fix: handle orderly shutdown from transport layer X-Git-Tag: v2.1.0~11 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=a6cd2b97ca69d302670109fef8340bd927270a30;p=lttng-tools.git Fix: handle orderly shutdown from transport layer Print a debug statement if a shutdown is detected or else an error. The transport layer will print the perror in case of an error. Signed-off-by: David Goulet --- diff --git a/src/bin/lttng-relayd/main.c b/src/bin/lttng-relayd/main.c index d0cf15a30..0446d9cb0 100644 --- a/src/bin/lttng-relayd/main.c +++ b/src/bin/lttng-relayd/main.c @@ -987,7 +987,12 @@ int relay_add_stream(struct lttcomm_relayd_hdr *recv_hdr, ret = cmd->sock->ops->recvmsg(cmd->sock, &stream_info, sizeof(struct lttcomm_relayd_add_stream), 0); if (ret < sizeof(struct lttcomm_relayd_add_stream)) { - ERR("Relay didn't receive valid add_stream struct size : %d", ret); + if (ret == 0) { + /* Orderly shutdown. Not necessary to print an error. */ + DBG("Socket %d did an orderly shutdown", cmd->sock->fd); + } else { + ERR("Relay didn't receive valid add_stream struct size : %d", ret); + } ret = -1; goto end_no_session; } @@ -1083,7 +1088,12 @@ int relay_close_stream(struct lttcomm_relayd_hdr *recv_hdr, ret = cmd->sock->ops->recvmsg(cmd->sock, &stream_info, sizeof(struct lttcomm_relayd_close_stream), 0); if (ret < sizeof(struct lttcomm_relayd_close_stream)) { - ERR("Relay didn't receive valid add_stream struct size : %d", ret); + if (ret == 0) { + /* Orderly shutdown. Not necessary to print an error. */ + DBG("Socket %d did an orderly shutdown", cmd->sock->fd); + } else { + ERR("Relay didn't receive valid add_stream struct size : %d", ret); + } ret = -1; goto end_no_session; } @@ -1289,8 +1299,13 @@ int relay_recv_metadata(struct lttcomm_relayd_hdr *recv_hdr, DBG2("Relay receiving metadata, waiting for %" PRIu64 " bytes", data_size); ret = cmd->sock->ops->recvmsg(cmd->sock, data_buffer, data_size, 0); if (ret < 0 || ret != data_size) { + if (ret == 0) { + /* Orderly shutdown. Not necessary to print an error. */ + DBG("Socket %d did an orderly shutdown", cmd->sock->fd); + } else { + ERR("Relay didn't receive the whole metadata"); + } ret = -1; - ERR("Relay didn't receive the whole metadata"); goto end; } metadata_struct = (struct lttcomm_relayd_metadata_payload *) data_buffer; @@ -1344,8 +1359,13 @@ int relay_send_version(struct lttcomm_relayd_hdr *recv_hdr, /* Get version from the other side. */ ret = cmd->sock->ops->recvmsg(cmd->sock, &msg, sizeof(msg), 0); if (ret < 0 || ret != sizeof(msg)) { + if (ret == 0) { + /* Orderly shutdown. Not necessary to print an error. */ + DBG("Socket %d did an orderly shutdown", cmd->sock->fd); + } else { + ERR("Relay failed to receive the version values."); + } ret = -1; - ERR("Relay failed to receive the version values."); goto end; } @@ -1402,7 +1422,13 @@ int relay_data_pending(struct lttcomm_relayd_hdr *recv_hdr, ret = cmd->sock->ops->recvmsg(cmd->sock, &msg, sizeof(msg), 0); if (ret < sizeof(msg)) { - ERR("Relay didn't receive valid data_pending struct size : %d", ret); + if (ret == 0) { + /* Orderly shutdown. Not necessary to print an error. */ + DBG("Socket %d did an orderly shutdown", cmd->sock->fd); + } else { + ERR("Relay didn't receive valid data_pending struct size : %d", + ret); + } ret = -1; goto end_no_session; } @@ -1479,8 +1505,13 @@ int relay_quiescent_control(struct lttcomm_relayd_hdr *recv_hdr, ret = cmd->sock->ops->recvmsg(cmd->sock, &msg, sizeof(msg), 0); if (ret < sizeof(msg)) { - ERR("Relay didn't receive valid begin data_pending struct size: %d", - ret); + if (ret == 0) { + /* Orderly shutdown. Not necessary to print an error. */ + DBG("Socket %d did an orderly shutdown", cmd->sock->fd); + } else { + ERR("Relay didn't receive valid begin data_pending struct size: %d", + ret); + } ret = -1; goto end_no_session; } @@ -1540,8 +1571,13 @@ int relay_begin_data_pending(struct lttcomm_relayd_hdr *recv_hdr, ret = cmd->sock->ops->recvmsg(cmd->sock, &msg, sizeof(msg), 0); if (ret < sizeof(msg)) { - ERR("Relay didn't receive valid begin data_pending struct size: %d", - ret); + if (ret == 0) { + /* Orderly shutdown. Not necessary to print an error. */ + DBG("Socket %d did an orderly shutdown", cmd->sock->fd); + } else { + ERR("Relay didn't receive valid begin data_pending struct size: %d", + ret); + } ret = -1; goto end_no_session; } @@ -1610,8 +1646,13 @@ int relay_end_data_pending(struct lttcomm_relayd_hdr *recv_hdr, ret = cmd->sock->ops->recvmsg(cmd->sock, &msg, sizeof(msg), 0); if (ret < sizeof(msg)) { - ERR("Relay didn't receive valid end data_pending struct size: %d", - ret); + if (ret == 0) { + /* Orderly shutdown. Not necessary to print an error. */ + DBG("Socket %d did an orderly shutdown", cmd->sock->fd); + } else { + ERR("Relay didn't receive valid end data_pending struct size: %d", + ret); + } ret = -1; goto end_no_session; } @@ -1711,7 +1752,12 @@ int relay_process_data(struct relay_command *cmd, struct lttng_ht *streams_ht) ret = cmd->sock->ops->recvmsg(cmd->sock, &data_hdr, sizeof(struct lttcomm_relayd_data_hdr), 0); if (ret <= 0) { - ERR("Connections seems to be closed"); + if (ret == 0) { + /* Orderly shutdown. Not necessary to print an error. */ + DBG("Socket %d did an orderly shutdown", cmd->sock->fd); + } else { + ERR("Unable to receive data header on sock %d", cmd->sock->fd); + } ret = -1; goto end; } @@ -1747,6 +1793,10 @@ int relay_process_data(struct relay_command *cmd, struct lttng_ht *streams_ht) data_size, stream_id, net_seq_num); ret = cmd->sock->ops->recvmsg(cmd->sock, data_buffer, data_size, 0); if (ret <= 0) { + if (ret == 0) { + /* Orderly shutdown. Not necessary to print an error. */ + DBG("Socket %d did an orderly shutdown", cmd->sock->fd); + } ret = -1; goto end_unlock; } diff --git a/src/bin/lttng-sessiond/consumer.c b/src/bin/lttng-sessiond/consumer.c index 26ff56eff..90c700129 100644 --- a/src/bin/lttng-sessiond/consumer.c +++ b/src/bin/lttng-sessiond/consumer.c @@ -45,7 +45,11 @@ int consumer_recv_status_reply(struct consumer_socket *sock) assert(sock); ret = lttcomm_recv_unix_sock(sock->fd, &reply, sizeof(reply)); - if (ret < 0) { + if (ret <= 0) { + if (ret == 0) { + /* Orderly shutdown. Don't return 0 which means success. */ + ret = -1; + } /* The above call will print a PERROR on error. */ DBG("Fail to receive status reply on sock %d", sock->fd); goto end; @@ -810,7 +814,11 @@ int consumer_is_data_pending(unsigned int id, */ ret = lttcomm_recv_unix_sock(socket->fd, &ret_code, sizeof(ret_code)); - if (ret < 0) { + if (ret <= 0) { + if (ret == 0) { + /* Orderly shutdown. Don't return 0 which means success. */ + ret = -1; + } /* The above call will print a PERROR on error. */ DBG("Error on recv consumer is data pending on sock %d", socket->fd); pthread_mutex_unlock(socket->lock);