Cleanup (messages): Make the wording of the signedness warning clearer
[babeltrace.git] / formats / ctf / ctf.c
index e3a487d6ef969f0ad2cd97c2ba360bb3a76c0937..cf9554739c6647701ecfd44132b7eacd80fdaa38 100644 (file)
@@ -147,6 +147,8 @@ uint64_t ctf_timestamp_begin(struct trace_descriptor *descriptor,
                struct ctf_stream_declaration *stream_class;
 
                stream_class = g_ptr_array_index(tin->streams, i);
+               if (!stream_class)
+                       continue;
                /* for each file_stream */
                for (j = 0; j < stream_class->streams->len; j++) {
                        struct ctf_stream_definition *stream;
@@ -190,6 +192,8 @@ uint64_t ctf_timestamp_end(struct trace_descriptor *descriptor,
                struct ctf_stream_declaration *stream_class;
 
                stream_class = g_ptr_array_index(tin->streams, i);
+               if (!stream_class)
+                       continue;
                /* for each file_stream */
                for (j = 0; j < stream_class->streams->len; j++) {
                        struct ctf_stream_definition *stream;
@@ -333,8 +337,6 @@ int ctf_read_event(struct stream_pos *ppos, struct ctf_stream_definition *stream
 
        /* save the current position as a restore point */
        pos->last_offset = pos->offset;
-       /* we just read the event, it is consumed when used by the caller */
-       stream->consumed = 0;
 
        /*
         * This is the EOF check after we've advanced the position in
@@ -904,6 +906,7 @@ int ctf_open_trace_metadata_read(struct ctf_trace *td,
        int ret = 0;
 
        metadata_stream = g_new0(struct ctf_file_stream, 1);
+       metadata_stream->pos.last_offset = LAST_OFFSET_POISON;
 
        if (packet_seek) {
                metadata_stream->pos.packet_seek = packet_seek;
@@ -1374,15 +1377,31 @@ int ctf_open_file_stream_read(struct ctf_trace *td, const char *path, int flags,
                void (*packet_seek)(struct stream_pos *pos, size_t index,
                        int whence))
 {
-       int ret;
+       int ret, fd;
        struct ctf_file_stream *file_stream;
+       struct stat statbuf;
 
-       ret = openat(td->dirfd, path, flags);
-       if (ret < 0) {
+       fd = openat(td->dirfd, path, flags);
+       if (fd < 0) {
                perror("File stream openat()");
+               ret = fd;
                goto error;
        }
+
+       /* Don't try to mmap subdirectories. Skip them, return success. */
+       ret = fstat(fd, &statbuf);
+       if (ret) {
+               perror("File stream fstat()");
+               goto fstat_error;
+       }
+       if (S_ISDIR(statbuf.st_mode)) {
+               fprintf(stderr, "[warning] Skipping directory '%s' found in trace\n", path);
+               ret = 0;
+               goto fd_is_dir_ok;
+       }
+
        file_stream = g_new0(struct ctf_file_stream, 1);
+       file_stream->pos.last_offset = LAST_OFFSET_POISON;
 
        if (packet_seek) {
                file_stream->pos.packet_seek = packet_seek;
@@ -1392,7 +1411,7 @@ int ctf_open_file_stream_read(struct ctf_trace *td, const char *path, int flags,
                goto error_def;
        }
 
-       ctf_init_pos(&file_stream->pos, ret, flags);
+       ctf_init_pos(&file_stream->pos, fd, flags);
        ret = create_trace_definitions(td, &file_stream->parent);
        if (ret)
                goto error_def;
@@ -1413,8 +1432,10 @@ error_index:
                definition_unref(&file_stream->parent.trace_packet_header->p);
 error_def:
        ctf_fini_pos(&file_stream->pos);
-       close(file_stream->pos.fd);
        g_free(file_stream);
+fd_is_dir_ok:
+fstat_error:
+       close(fd);
 error:
        return ret;
 }
@@ -1603,6 +1624,7 @@ int ctf_open_mmap_stream_read(struct ctf_trace *td,
        struct ctf_file_stream *file_stream;
 
        file_stream = g_new0(struct ctf_file_stream, 1);
+       file_stream->pos.last_offset = LAST_OFFSET_POISON;
        ctf_init_mmap_pos(&file_stream->pos, mmap_info);
 
        file_stream->pos.packet_seek = packet_seek;
This page took 0.024976 seconds and 4 git commands to generate.