Make lttng_directory_handle reference countable
[lttng-tools.git] / src / common / kernel-consumer / kernel-consumer.c
index 196da6633353a44ea6f73821494642e0cd7539a3..fdd9ca65b05e8617299ee5909f11e886f8679a37 100644 (file)
@@ -1145,7 +1145,7 @@ end_destroy_channel:
                ret = consumer_send_status_msg(sock, ret_code);
                if (ret < 0) {
                        /* Somehow, the session daemon is not responding anymore. */
-                       goto end_nosignal;
+                       goto error_rotate_channel;
                }
                if (channel) {
                        /* Rotate the streams that are ready right now. */
@@ -1155,8 +1155,9 @@ end_destroy_channel:
                                ERR("Rotate ready streams failed");
                        }
                }
-
                break;
+error_rotate_channel:
+               goto end_nosignal;
        }
        case LTTNG_CONSUMER_INIT:
        {
@@ -1184,8 +1185,7 @@ end_destroy_channel:
                                *msg.u.create_trace_chunk.override_name ?
                                        msg.u.create_trace_chunk.override_name :
                                        NULL;
-               LTTNG_OPTIONAL(struct lttng_directory_handle) chunk_directory_handle =
-                               LTTNG_OPTIONAL_INIT;
+               struct lttng_directory_handle *chunk_directory_handle = NULL;
 
                /*
                 * The session daemon will only provide a chunk directory file
@@ -1210,17 +1210,15 @@ end_destroy_channel:
 
                        DBG("Received trace chunk directory fd (%d)",
                                        chunk_dirfd);
-                       ret = lttng_directory_handle_init_from_dirfd(
-                                       &chunk_directory_handle.value,
+                       chunk_directory_handle = lttng_directory_handle_create_from_dirfd(
                                        chunk_dirfd);
-                       if (ret) {
+                       if (!chunk_directory_handle) {
                                ERR("Failed to initialize chunk directory handle from directory file descriptor");
                                if (close(chunk_dirfd)) {
                                        PERROR("Failed to close chunk directory file descriptor");
                                }
                                goto error_fatal;
                        }
-                       chunk_directory_handle.is_set = true;
                }
 
                ret_code = lttng_consumer_create_trace_chunk(
@@ -1233,14 +1231,8 @@ end_destroy_channel:
                                msg.u.create_trace_chunk.credentials.is_set ?
                                                &credentials :
                                                NULL,
-                               chunk_directory_handle.is_set ?
-                                               &chunk_directory_handle.value :
-                                               NULL);
-
-               if (chunk_directory_handle.is_set) {
-                       lttng_directory_handle_fini(
-                                       &chunk_directory_handle.value);
-               }
+                               chunk_directory_handle);
+               lttng_directory_handle_put(chunk_directory_handle);
                goto end_msg_sessiond;
        }
        case LTTNG_CONSUMER_CLOSE_TRACE_CHUNK:
@@ -1249,6 +1241,8 @@ end_destroy_channel:
                                msg.u.close_trace_chunk.close_command.value;
                const uint64_t relayd_id =
                                msg.u.close_trace_chunk.relayd_id.value;
+               struct lttcomm_consumer_close_trace_chunk_reply reply;
+               char path[LTTNG_PATH_MAX];
 
                ret_code = lttng_consumer_close_trace_chunk(
                                msg.u.close_trace_chunk.relayd_id.is_set ?
@@ -1259,8 +1253,18 @@ end_destroy_channel:
                                (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;
+                                               NULL, path);
+               reply.ret_code = ret_code;
+               reply.path_length = strlen(path) + 1;
+               ret = lttcomm_send_unix_sock(sock, &reply, sizeof(reply));
+               if (ret != sizeof(reply)) {
+                       goto error_fatal;
+               }
+               ret = lttcomm_send_unix_sock(sock, path, reply.path_length);
+               if (ret != reply.path_length) {
+                       goto error_fatal;
+               }
+               goto end_nosignal;
        }
        case LTTNG_CONSUMER_TRACE_CHUNK_EXISTS:
        {
@@ -1314,66 +1318,62 @@ end:
 static int get_index_values(struct ctf_packet_index *index, int infd)
 {
        int ret;
+       uint64_t packet_size, content_size, timestamp_begin, timestamp_end,
+                       events_discarded, stream_id, stream_instance_id,
+                       packet_seq_num;
 
-       ret = kernctl_get_timestamp_begin(infd, &index->timestamp_begin);
+       ret = kernctl_get_timestamp_begin(infd, &timestamp_begin);
        if (ret < 0) {
                PERROR("kernctl_get_timestamp_begin");
                goto error;
        }
-       index->timestamp_begin = htobe64(index->timestamp_begin);
 
-       ret = kernctl_get_timestamp_end(infd, &index->timestamp_end);
+       ret = kernctl_get_timestamp_end(infd, &timestamp_end);
        if (ret < 0) {
                PERROR("kernctl_get_timestamp_end");
                goto error;
        }
-       index->timestamp_end = htobe64(index->timestamp_end);
 
-       ret = kernctl_get_events_discarded(infd, &index->events_discarded);
+       ret = kernctl_get_events_discarded(infd, &events_discarded);
        if (ret < 0) {
                PERROR("kernctl_get_events_discarded");
                goto error;
        }
-       index->events_discarded = htobe64(index->events_discarded);
 
-       ret = kernctl_get_content_size(infd, &index->content_size);
+       ret = kernctl_get_content_size(infd, &content_size);
        if (ret < 0) {
                PERROR("kernctl_get_content_size");
                goto error;
        }
-       index->content_size = htobe64(index->content_size);
 
-       ret = kernctl_get_packet_size(infd, &index->packet_size);
+       ret = kernctl_get_packet_size(infd, &packet_size);
        if (ret < 0) {
                PERROR("kernctl_get_packet_size");
                goto error;
        }
-       index->packet_size = htobe64(index->packet_size);
 
-       ret = kernctl_get_stream_id(infd, &index->stream_id);
+       ret = kernctl_get_stream_id(infd, &stream_id);
        if (ret < 0) {
                PERROR("kernctl_get_stream_id");
                goto error;
        }
-       index->stream_id = htobe64(index->stream_id);
 
-       ret = kernctl_get_instance_id(infd, &index->stream_instance_id);
+       ret = kernctl_get_instance_id(infd, &stream_instance_id);
        if (ret < 0) {
                if (ret == -ENOTTY) {
                        /* Command not implemented by lttng-modules. */
-                       index->stream_instance_id = -1ULL;
+                       stream_instance_id = -1ULL;
                } else {
                        PERROR("kernctl_get_instance_id");
                        goto error;
                }
        }
-       index->stream_instance_id = htobe64(index->stream_instance_id);
 
-       ret = kernctl_get_sequence_number(infd, &index->packet_seq_num);
+       ret = kernctl_get_sequence_number(infd, &packet_seq_num);
        if (ret < 0) {
                if (ret == -ENOTTY) {
                        /* Command not implemented by lttng-modules. */
-                       index->packet_seq_num = -1ULL;
+                       packet_seq_num = -1ULL;
                        ret = 0;
                } else {
                        PERROR("kernctl_get_sequence_number");
@@ -1382,6 +1382,18 @@ static int get_index_values(struct ctf_packet_index *index, int infd)
        }
        index->packet_seq_num = htobe64(index->packet_seq_num);
 
+       *index = (typeof(*index)) {
+               .offset = index->offset,
+               .packet_size = htobe64(packet_size),
+               .content_size = htobe64(content_size),
+               .timestamp_begin = htobe64(timestamp_begin),
+               .timestamp_end = htobe64(timestamp_end),
+               .events_discarded = htobe64(events_discarded),
+               .stream_id = htobe64(stream_id),
+               .stream_instance_id = htobe64(stream_instance_id),
+               .packet_seq_num = htobe64(packet_seq_num),
+       };
+
 error:
        return ret;
 }
@@ -1532,7 +1544,7 @@ ssize_t lttng_kconsumer_read_subbuffer(struct lttng_consumer_stream *stream,
        int err, write_index = 1, rotation_ret;
        ssize_t ret = 0;
        int infd = stream->wait_fd;
-       struct ctf_packet_index index;
+       struct ctf_packet_index index = {};
 
        DBG("In read_subbuffer (infd : %d)", infd);
 
This page took 0.026791 seconds and 5 git commands to generate.