From f4f0fb70266576f726efa583130680746df4c172 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Sun, 4 Jan 2015 21:17:30 -0500 Subject: [PATCH] Fix: allow empty CTF files 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 --- formats/ctf/ctf.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index 58b54889..40da01da 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -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); -- 2.34.1