Fix: relayd stream.c: LTTNG_OPTIONAL_GET address confusion
[lttng-tools.git] / src / bin / lttng-relayd / stream.c
index 9d753bd0a7037c042c6218487d0bda0a4d95a0b4..755fb6734072113af804e59f6e1e81089adb6b1f 100644 (file)
@@ -90,7 +90,6 @@ static int stream_create_data_output_file_from_trace_chunk(
        const mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
 
        ASSERT_LOCKED(stream->lock);
-       assert(stream->trace_chunk);
 
        ret = utils_stream_file_path(stream->path_name, stream->channel_name,
                        stream->tracefile_size, stream->tracefile_current_index,
@@ -210,7 +209,7 @@ static int rotate_truncate_stream(struct relay_stream *stream)
        struct stream_fd *previous_stream_fd = NULL;
        struct lttng_trace_chunk *previous_chunk = NULL;
 
-       if (!LTTNG_OPTIONAL_GET(&stream->ongoing_rotation)->next_trace_chunk) {
+       if (!LTTNG_OPTIONAL_GET(stream->ongoing_rotation).next_trace_chunk) {
                ERR("Protocol error encoutered in %s(): stream rotation "
                        "sequence number is before the current sequence number "
                        "and the next trace chunk is unset. Honoring this "
@@ -955,6 +954,14 @@ int stream_init_packet(struct relay_stream *stream, size_t packet_size,
        int ret = 0;
 
        ASSERT_LOCKED(stream->lock);
+
+       if (!stream->stream_fd || !stream->trace_chunk) {
+               ERR("Protocol error: received a packet for a stream that doesn't have a current trace chunk: stream_id = %" PRIu64 ", channel_name = %s",
+                               stream->stream_handle, stream->channel_name);
+               ret = -1;
+               goto end;
+       }
+
        if (caa_likely(stream->tracefile_size == 0)) {
                /* No size limit set; nothing to check. */
                goto end;
@@ -1020,6 +1027,12 @@ int stream_write(struct relay_stream *stream,
        memset(padding_buffer, 0,
                        min(sizeof(padding_buffer), padding_to_write));
 
+       if (!stream->stream_fd || !stream->trace_chunk) {
+               ERR("Protocol error: received a packet for a stream that doesn't have a current trace chunk: stream_id = %" PRIu64 ", channel_name = %s",
+                               stream->stream_handle, stream->channel_name);
+               ret = -1;
+               goto end;
+       }
        if (packet) {
                write_ret = lttng_write(stream->stream_fd->fd,
                                packet->data, packet->size);
This page took 0.024165 seconds and 4 git commands to generate.