page-xfer: handle a case when splice returns zero

Submitted by Andrei Vagin on July 20, 2017, 2:31 a.m.

Details

Message ID 20170720023143.32331-1-avagin@openvz.org
State Accepted
Series "page-xfer: handle a case when splice returns zero"
Headers show

Commit Message

Andrei Vagin July 20, 2017, 2:31 a.m.
From: Andrei Vagin <avagin@virtuozzo.com>

A return value of 0 means end of input, so we need to
stop reading from this descriptor.

Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
---
 criu/page-xfer.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Patch hide | download patch | download mbox

diff --git a/criu/page-xfer.c b/criu/page-xfer.c
index 49693bb..56b7c91 100644
--- a/criu/page-xfer.c
+++ b/criu/page-xfer.c
@@ -182,6 +182,10 @@  static int write_pages_loc(struct page_xfer *xfer,
 			pr_perror("Unable to spice data");
 			return -1;
 		}
+		if (ret == 0) {
+			pr_err("A pipe was closed unexpectedly");
+			return -1;
+		}
 		curr += ret;
 		if (curr == len)
 			break;
@@ -652,6 +656,10 @@  static int page_server_add(int sk, struct page_server_iov *pi, u32 flags)
 			pr_perror("Can't read from socket");
 			return -1;
 		}
+		if (chunk == 0) {
+			pr_err("A socket was closed unexpectedly");
+			return -1;
+		}
 
 		if (lxfer->write_pages(lxfer, cxfer.p[0], chunk))
 			return -1;