Use case-scope error labels handling LTTNG_CONSUMER_PUSH_METADATA
[lttng-tools.git] / src / common / ust-consumer / ust-consumer.c
index ff9d31d5287a92b29bf6ac16bff0e6a17876d837..ee6f4f79b9147a9feb22e046b86402973382c19b 100644 (file)
@@ -519,7 +519,8 @@ error_open:
        if (channel->root_shm_path[0]) {
                (void) run_as_rmdir_recursive(channel->root_shm_path,
                                channel->buffer_credentials.value.uid,
-                               channel->buffer_credentials.value.gid);
+                               channel->buffer_credentials.value.gid,
+                               LTTNG_DIRECTORY_HANDLE_SKIP_NON_EMPTY_FLAG);
        }
        free(stream_fds);
 error_alloc:
@@ -1590,7 +1591,7 @@ int lttng_ustconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,
                if (!channel) {
                        ERR("UST consumer get channel key %" PRIu64 " not found", key);
                        ret_code = LTTCOMM_CONSUMERD_CHAN_NOT_FOUND;
-                       goto end_msg_sessiond;
+                       goto end_get_channel;
                }
 
                health_code_update();
@@ -1606,13 +1607,13 @@ int lttng_ustconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,
                                 * and the consumer can continue its work. The above call
                                 * has sent the error status message to the sessiond.
                                 */
-                               goto end_nosignal;
+                               goto end_get_channel_nosignal;
                        }
                        /*
                         * The communicaton was broken hence there is a bad state between
                         * the consumer and sessiond so stop everything.
                         */
-                       goto error_fatal;
+                       goto error_get_channel_fatal;
                }
 
                health_code_update();
@@ -1622,7 +1623,7 @@ int lttng_ustconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,
                 * so don't send them to the data thread.
                 */
                if (!channel->monitor) {
-                       goto end_msg_sessiond;
+                       goto end_get_channel;
                }
 
                ret = send_streams_to_thread(channel, ctx);
@@ -1631,11 +1632,16 @@ int lttng_ustconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,
                         * If we are unable to send the stream to the thread, there is
                         * a big problem so just stop everything.
                         */
-                       goto error_fatal;
+                       goto error_get_channel_fatal;
                }
                /* List MUST be empty after or else it could be reused. */
                assert(cds_list_empty(&channel->streams.head));
+end_get_channel:
                goto end_msg_sessiond;
+error_get_channel_fatal:
+               goto error_fatal;
+end_get_channel_nosignal:
+               goto end_nosignal;
        }
        case LTTNG_CONSUMER_DESTROY_CHANNEL:
        {
@@ -1706,7 +1712,7 @@ int lttng_ustconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,
                         */
                        DBG("UST consumer push metadata %" PRIu64 " not found", key);
                        ret_code = LTTCOMM_CONSUMERD_CHANNEL_FAIL;
-                       goto end_msg_sessiond;
+                       goto end_push_metadata_msg_sessiond;
                }
 
                health_code_update();
@@ -1717,14 +1723,14 @@ int lttng_ustconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,
                         * checked whether the channel can be found.
                         */
                        ret_code = LTTCOMM_CONSUMERD_SUCCESS;
-                       goto end_msg_sessiond;
+                       goto end_push_metadata_msg_sessiond;
                }
 
                /* Tell session daemon we are ready to receive the metadata. */
                ret = consumer_send_status_msg(sock, LTTCOMM_CONSUMERD_SUCCESS);
                if (ret < 0) {
                        /* Somehow, the session daemon is not responding anymore. */
-                       goto error_fatal;
+                       goto error_push_metadata_fatal;
                }
 
                health_code_update();
@@ -1734,7 +1740,7 @@ int lttng_ustconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,
                ret = lttng_consumer_poll_socket(consumer_sockpoll);
                health_poll_exit();
                if (ret) {
-                       goto error_fatal;
+                       goto error_push_metadata_fatal;
                }
 
                health_code_update();
@@ -1743,11 +1749,15 @@ int lttng_ustconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,
                                len, version, channel, 0, 1);
                if (ret < 0) {
                        /* error receiving from sessiond */
-                       goto error_fatal;
+                       goto error_push_metadata_fatal;
                } else {
                        ret_code = ret;
-                       goto end_msg_sessiond;
+                       goto end_push_metadata_msg_sessiond;
                }
+end_push_metadata_msg_sessiond:
+               goto end_msg_sessiond;
+error_push_metadata_fatal:
+               goto error_fatal;
        }
        case LTTNG_CONSUMER_SETUP_METADATA:
        {
@@ -2008,8 +2018,8 @@ int lttng_ustconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,
        case LTTNG_CONSUMER_CREATE_TRACE_CHUNK:
        {
                const struct lttng_credentials credentials = {
-                       .uid = msg.u.create_trace_chunk.credentials.uid,
-                       .gid = msg.u.create_trace_chunk.credentials.gid,
+                       .uid = msg.u.create_trace_chunk.credentials.value.uid,
+                       .gid = msg.u.create_trace_chunk.credentials.value.gid,
                };
                const bool is_local_trace =
                                !msg.u.create_trace_chunk.relayd_id.is_set;
@@ -2062,9 +2072,12 @@ int lttng_ustconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,
                                !is_local_trace ? &relayd_id : NULL,
                                msg.u.create_trace_chunk.session_id,
                                msg.u.create_trace_chunk.chunk_id,
-                               (time_t) msg.u.create_trace_chunk.creation_timestamp,
+                               (time_t) msg.u.create_trace_chunk
+                                               .creation_timestamp,
                                chunk_override_name,
-                               &credentials,
+                               msg.u.create_trace_chunk.credentials.is_set ?
+                                               &credentials :
+                                               NULL,
                                chunk_directory_handle.is_set ?
                                                &chunk_directory_handle.value :
                                                NULL);
@@ -2077,15 +2090,21 @@ int lttng_ustconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,
        }
        case LTTNG_CONSUMER_CLOSE_TRACE_CHUNK:
        {
+               enum lttng_trace_chunk_command_type close_command =
+                               msg.u.close_trace_chunk.close_command.value;
                const uint64_t relayd_id =
                                msg.u.close_trace_chunk.relayd_id.value;
 
                ret_code = lttng_consumer_close_trace_chunk(
                                msg.u.close_trace_chunk.relayd_id.is_set ?
-                                               &relayd_id : NULL,
+                                               &relayd_id :
+                                               NULL,
                                msg.u.close_trace_chunk.session_id,
                                msg.u.close_trace_chunk.chunk_id,
-                               (time_t) msg.u.close_trace_chunk.close_timestamp);
+                               (time_t) msg.u.close_trace_chunk.close_timestamp,
+                               msg.u.close_trace_chunk.close_command.is_set ?
+                                               &close_command :
+                                               NULL);
                goto end_msg_sessiond;
        }
        case LTTNG_CONSUMER_TRACE_CHUNK_EXISTS:
@@ -2105,15 +2124,12 @@ int lttng_ustconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,
        }
 
 end_nosignal:
-       rcu_read_unlock();
-
-       health_code_update();
-
        /*
         * Return 1 to indicate success since the 0 value can be a socket
         * shutdown during the recv() or send() call.
         */
-       return 1;
+       ret = 1;
+       goto end;
 
 end_msg_sessiond:
        /*
@@ -2125,11 +2141,9 @@ end_msg_sessiond:
        if (ret < 0) {
                goto error_fatal;
        }
-       rcu_read_unlock();
-
-       health_code_update();
+       ret = 1;
+       goto end;
 
-       return 1;
 end_channel_error:
        if (channel) {
                pthread_mutex_unlock(&channel->lock);
@@ -2145,15 +2159,18 @@ end_channel_error:
                /* Stop everything if session daemon can not be notified. */
                goto error_fatal;
        }
-       rcu_read_unlock();
-
-       health_code_update();
+       ret = 1;
+       goto end;
 
-       return 1;
 error_fatal:
-       rcu_read_unlock();
        /* This will issue a consumer stop. */
-       return -1;
+       ret = -1;
+       goto end;
+
+end:
+       rcu_read_unlock();
+       health_code_update();
+       return ret;
 }
 
 /*
@@ -2340,7 +2357,8 @@ void lttng_ustconsumer_free_channel(struct lttng_consumer_channel *chan)
        if (chan->root_shm_path[0]) {
                (void) run_as_rmdir_recursive(chan->root_shm_path,
                                chan->buffer_credentials.value.uid,
-                               chan->buffer_credentials.value.gid);
+                               chan->buffer_credentials.value.gid,
+                               LTTNG_DIRECTORY_HANDLE_SKIP_NON_EMPTY_FLAG);
        }
        free(chan->stream_fds);
 }
This page took 0.02676 seconds and 4 git commands to generate.