Skip to contentSkip to conversation

iowatcher: gracefully skip zero-length trace files

PATCH New Eric Sandeen 1 participant 1 message Aug 20, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iowatcher: gracefully skip zero-length trace files

I received a bug report where this result confused the reporter:

# iowatcher -t dump.blktrace.1 -o movie.ogg  --movie=rect
Using movie style: rect
Unable to mmap trace file dump.blktrace.1, err Invalid argument
#

mmap() failed because the specified trace file was zero length. Since mmap will fail, and we can't use a zero-length file anyway, make the error more clear and don't even try the mmap.

---

iowatcher/blkparse.c +4 -0
index 41e20f0..c56e017 100644
@@ -930,6 +930,10 @@ struct trace *open_trace(char *filename)
 		fprintf(stderr, "stat failed on %s err %s\n", filename, strerror(errno));
 		goto fail_fd;
 	}
+	if (!st.st_size) {
+		fprintf(stderr, "skipping zero-length file %s\n", filename);
+		goto fail_fd;
+	}
 	p = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
 	if (p = MAP_FAILED) {
 		fprintf(stderr, "Unable to mmap trace file %s, err %s\n", filename, strerror(errno));