Fix: allow empty CTF files
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 5 Jan 2015 02:17:30 +0000 (21:17 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 5 Jan 2015 21:55:57 +0000 (16:55 -0500)
There are expected situtations in which CTF producers (like LTTng) can
generate empty CTF trace files. The current babeltrace behavior is to
trigger an error when an empty file is encountered. Change this to allow
reading the rest of the trace anyway.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf/ctf.c

index 58b5488920d006e71aafe96b764e5f49ec7c5b6d..40da01da2d57619d1257fc42a4666923afaaeaa2 100644 (file)
@@ -1964,6 +1964,11 @@ int ctf_open_file_stream_read(struct ctf_trace *td, const char *path, int flags,
                ret = 0;
                goto fd_is_dir_ok;
        }
+       if (!statbuf.st_size) {
+               /** Skip empty files. */
+               ret = 0;
+               goto fd_is_empty_file;
+       }
 
        file_stream = g_new0(struct ctf_file_stream, 1);
        file_stream->pos.last_offset = LAST_OFFSET_POISON;
@@ -1998,6 +2003,7 @@ int ctf_open_file_stream_read(struct ctf_trace *td, const char *path, int flags,
        index_name = malloc((strlen(path) + sizeof(INDEX_PATH)) * sizeof(char));
        if (!index_name) {
                fprintf(stderr, "[error] Cannot allocate index filename\n");
+               ret = -ENOMEM;
                goto error_def;
        }
        snprintf(index_name, strlen(path) + sizeof(INDEX_PATH),
@@ -2056,6 +2062,7 @@ error_def:
                fprintf(stderr, "Error on ctf_fini_pos\n");
        }
        g_free(file_stream);
+fd_is_empty_file:
 fd_is_dir_ok:
 fstat_error:
        closeret = close(fd);
This page took 0.026498 seconds and 4 git commands to generate.