iowatcher: gracefully skip zero-length trace files
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.
Reported-by Karel Srot <[email protected]>
Signed-off-by Eric Sandeen <[email protected]>
---
iowatcher/blkparse.c +4 -0
@@ -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));