Fix: consumer_add_relayd_socket() report errors to sessiond
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 2 Jul 2013 19:14:02 +0000 (15:14 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Thu, 4 Jul 2013 16:25:06 +0000 (12:25 -0400)
Wait until the side-effect to relayd is actually performed before
replying that "all is fine" to sessiond.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
src/common/consumer.c
src/common/sessiond-comm/sessiond-comm.c
src/common/sessiond-comm/sessiond-comm.h

index a1a99b4012e5b8f8e50b013f6afeb697509cab8d..560ec6cd06a24366daf5879fb779c4aa6a19ff4d 100644 (file)
@@ -3092,8 +3092,9 @@ int consumer_add_relayd_socket(uint64_t net_seq_idx, int sock_type,
                /* Not found. Allocate one. */
                relayd = consumer_allocate_relayd_sock_pair(net_seq_idx);
                if (relayd == NULL) {
-                       ret_code = LTTCOMM_CONSUMERD_ENOMEM;
                        ret = -ENOMEM;
+                       ret_code = LTTCOMM_CONSUMERD_ENOMEM;
+                       goto error;
                } else {
                        relayd->sessiond_session_id = sessiond_id;
                        relayd_created = 1;
@@ -3112,23 +3113,23 @@ int consumer_add_relayd_socket(uint64_t net_seq_idx, int sock_type,
        }
 
        /* First send a status message before receiving the fds. */
-       ret = consumer_send_status_msg(sock, ret_code);
-       if (ret < 0 || ret_code != LTTNG_OK) {
+       ret = consumer_send_status_msg(sock, LTTNG_OK);
+       if (ret < 0) {
                /* Somehow, the session daemon is not responding anymore. */
-               goto error;
+               lttng_consumer_send_error(ctx, LTTCOMM_CONSUMERD_FATAL);
+               goto error_nosignal;
        }
 
        /* Poll on consumer socket. */
        if (lttng_consumer_poll_socket(consumer_sockpoll) < 0) {
                lttng_consumer_send_error(ctx, LTTCOMM_CONSUMERD_POLL_ERROR);
                ret = -EINTR;
-               goto error;
+               goto error_nosignal;
        }
 
        /* Get relayd socket from session daemon */
        ret = lttcomm_recv_fds_unix_sock(sock, &fd, 1);
        if (ret != sizeof(fd)) {
-               ret_code = LTTCOMM_CONSUMERD_ERROR_RECV_FD;
                ret = -1;
                fd = -1;        /* Just in case it gets set with an invalid value. */
 
@@ -3142,18 +3143,7 @@ int consumer_add_relayd_socket(uint64_t net_seq_idx, int sock_type,
                 * issue when reaching the fd limit.
                 */
                lttng_consumer_send_error(ctx, LTTCOMM_CONSUMERD_ERROR_RECV_FD);
-
-               /*
-                * This code path MUST continue to the consumer send status message so
-                * we can send the error to the thread expecting a reply. The above
-                * call will make everything stop.
-                */
-       }
-
-       /* We have the fds without error. Send status back. */
-       ret = consumer_send_status_msg(sock, ret_code);
-       if (ret < 0 || ret_code != LTTNG_OK) {
-               /* Somehow, the session daemon is not responding anymore. */
+               ret_code = LTTCOMM_CONSUMERD_ERROR_RECV_FD;
                goto error;
        }
 
@@ -3165,6 +3155,7 @@ int consumer_add_relayd_socket(uint64_t net_seq_idx, int sock_type,
                ret = lttcomm_create_sock(&relayd->control_sock.sock);
                /* Handle create_sock error. */
                if (ret < 0) {
+                       ret_code = LTTCOMM_CONSUMERD_ENOMEM;
                        goto error;
                }
                /*
@@ -3203,6 +3194,7 @@ int consumer_add_relayd_socket(uint64_t net_seq_idx, int sock_type,
                         */
                        (void) relayd_close(&relayd->control_sock);
                        (void) relayd_close(&relayd->data_sock);
+                       ret_code = LTTCOMM_CONSUMERD_RELAYD_FAIL;
                        goto error;
                }
 
@@ -3213,6 +3205,7 @@ int consumer_add_relayd_socket(uint64_t net_seq_idx, int sock_type,
                ret = lttcomm_create_sock(&relayd->data_sock.sock);
                /* Handle create_sock error. */
                if (ret < 0) {
+                       ret_code = LTTCOMM_CONSUMERD_ENOMEM;
                        goto error;
                }
                /*
@@ -3234,6 +3227,7 @@ int consumer_add_relayd_socket(uint64_t net_seq_idx, int sock_type,
        default:
                ERR("Unknown relayd socket type (%d)", sock_type);
                ret = -1;
+               ret_code = LTTCOMM_CONSUMERD_FATAL;
                goto error;
        }
 
@@ -3241,6 +3235,14 @@ int consumer_add_relayd_socket(uint64_t net_seq_idx, int sock_type,
                        sock_type == LTTNG_STREAM_CONTROL ? "control" : "data",
                        relayd->net_seq_idx, fd);
 
+       /* We successfully added the socket. Send status back. */
+       ret = consumer_send_status_msg(sock, ret_code);
+       if (ret < 0) {
+               /* Somehow, the session daemon is not responding anymore. */
+               lttng_consumer_send_error(ctx, LTTCOMM_CONSUMERD_FATAL);
+               goto error_nosignal;
+       }
+
        /*
         * Add relayd socket pair to consumer data hashtable. If object already
         * exists or on error, the function gracefully returns.
@@ -3251,6 +3253,11 @@ int consumer_add_relayd_socket(uint64_t net_seq_idx, int sock_type,
        return 0;
 
 error:
+       if (consumer_send_status_msg(sock, ret_code) < 0) {
+               lttng_consumer_send_error(ctx, LTTCOMM_CONSUMERD_FATAL);
+       }
+
+error_nosignal:
        /* Close received socket if valid. */
        if (fd >= 0) {
                if (close(fd)) {
index 738362c1a6f2c533fd43ed38c829e5386e7dcd66..9a13f41488a9ef6deb61323cf403f7ed8688da1a 100644 (file)
@@ -64,6 +64,7 @@ static const char *lttcomm_readable_code[] = {
        [ LTTCOMM_ERR_INDEX(LTTCOMM_CONSUMERD_ENOMEM) ] = "Consumer is out of memory",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_CONSUMERD_ERROR_METADATA) ] = "Error with metadata",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_CONSUMERD_FATAL) ] = "Fatal error",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_CONSUMERD_RELAYD_FAIL) ] = "Error on remote relayd",
 
        /* Last element */
        [ LTTCOMM_ERR_INDEX(LTTCOMM_NR) ] = "Unknown error code"
index 64c8d1879063921cffb8285dee13151b474b0a51..0c49a3c535d4af8f0abd6e01b1a26b7698d21ab0 100644 (file)
@@ -119,6 +119,7 @@ enum lttcomm_return_code {
        LTTCOMM_CONSUMERD_ENOMEM,                   /* Consumer is out of memory */
        LTTCOMM_CONSUMERD_ERROR_METADATA,           /* Error with metadata. */
        LTTCOMM_CONSUMERD_FATAL,                    /* Fatal error. */
+       LTTCOMM_CONSUMERD_RELAYD_FAIL,              /* Error on remote relayd */
 
        /* MUST be last element */
        LTTCOMM_NR,                                             /* Last element */
This page took 0.030427 seconds and 4 git commands to generate.