Fix: handle orderly shutdown from transport layer
authorDavid Goulet <dgoulet@efficios.com>
Wed, 19 Dec 2012 23:25:49 +0000 (18:25 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Wed, 19 Dec 2012 23:25:51 +0000 (18:25 -0500)
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 <dgoulet@efficios.com>
src/bin/lttng-relayd/main.c
src/bin/lttng-sessiond/consumer.c

index d0cf15a30febfa0602a4b377387fbe947e521a2d..0446d9cb04dcddce51d919ca6d0e27160ed25bdc 100644 (file)
@@ -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;
        }
index 26ff56effe8f57715822badae8d8df2ade6c092e..90c700129159129876fb1d54ac19bb9f566dde3b 100644 (file)
@@ -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);
This page took 0.028969 seconds and 4 git commands to generate.