With "-t -" the trace is read from a pipe, where read() may return
fewer bytes than requested, which was reported as an I/O error.
Loop until the whole record is read, retrying on EINTR.
Without zlib this is how a compressed trace has to be replayed:
$ gunzip -c trace.gz | risu -t - image.bin
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
risu.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/risu.c b/risu.c
index c28b4a5..ba307f4 100644
--- a/risu.c
+++ b/risu.c
@@ -68,7 +68,21 @@ static RisuResult read_buffer(void *ptr, size_t bytes)
#ifdef HAVE_ZLIB
if (comm_fd == STDIN_FILENO) {
#endif
- res = read(comm_fd, ptr, bytes);
+ /* A pipe can return short reads: loop until we have it all. */
+ char *p = ptr;
+
+ res = 0;
+ while (res < bytes) {
+ ssize_t r = read(comm_fd, p + res, bytes - res);
+
+ if (r < 0 && errno == EINTR) {
+ continue;
+ }
+ if (r <= 0) {
+ break;
+ }
+ res += r;
+ }
#ifdef HAVE_ZLIB
} else {
res = gzread(gz_trace_file, ptr, bytes);
--
2.55.0