+ trace_chunk = NULL;
+ goto end;
+}
+
+int session_close_trace_chunk(const struct ltt_session *session,
+ struct lttng_trace_chunk *trace_chunk,
+ const enum lttng_trace_chunk_command_type *close_command,
+ char *closed_trace_chunk_path)
+{
+ int ret = 0;
+ bool error_occurred = false;
+ struct cds_lfht_iter iter;
+ struct consumer_socket *socket;
+ enum lttng_trace_chunk_status chunk_status;
+ const time_t chunk_close_timestamp = time(NULL);
+
+ if (close_command) {
+ chunk_status = lttng_trace_chunk_set_close_command(
+ trace_chunk, *close_command);
+ if (chunk_status != LTTNG_TRACE_CHUNK_STATUS_OK) {
+ ret = -1;
+ goto end;
+ }
+ }
+
+ if (chunk_close_timestamp == (time_t) -1) {
+ ERR("Failed to sample the close timestamp of the current trace chunk of session \"%s\"",
+ session->name);
+ ret = -1;
+ goto end;
+ }
+ chunk_status = lttng_trace_chunk_set_close_timestamp(trace_chunk,
+ chunk_close_timestamp);
+ if (chunk_status != LTTNG_TRACE_CHUNK_STATUS_OK) {
+ ERR("Failed to set the close timestamp of the current trace chunk of session \"%s\"",
+ session->name);
+ ret = -1;
+ goto end;
+ }
+
+ if (session->ust_session) {
+ const uint64_t relayd_id =
+ session->ust_session->consumer->net_seq_index;
+
+ cds_lfht_for_each_entry(
+ session->ust_session->consumer->socks->ht,
+ &iter, socket, node.node) {
+ pthread_mutex_lock(socket->lock);
+ ret = consumer_close_trace_chunk(socket,
+ relayd_id,
+ session->id,
+ trace_chunk, closed_trace_chunk_path);
+ pthread_mutex_unlock(socket->lock);
+ if (ret) {
+ ERR("Failed to close trace chunk on user space consumer");
+ error_occurred = true;
+ }
+ }
+ }
+ if (session->kernel_session) {
+ const uint64_t relayd_id =
+ session->kernel_session->consumer->net_seq_index;
+
+ cds_lfht_for_each_entry(
+ session->kernel_session->consumer->socks->ht,
+ &iter, socket, node.node) {
+ pthread_mutex_lock(socket->lock);
+ ret = consumer_close_trace_chunk(socket,
+ relayd_id,
+ session->id,
+ trace_chunk, closed_trace_chunk_path);
+ pthread_mutex_unlock(socket->lock);
+ if (ret) {
+ ERR("Failed to close trace chunk on kernel consumer");
+ error_occurred = true;
+ }
+ }
+ }
+ ret = error_occurred ? -1 : 0;