[Pdbg] [PATCH] Revert "htm: Use splice() to copy dump"

Rashmica Gupta rashmica.g at gmail.com
Thu Nov 26 13:38:14 AEDT 2020


This reverts commit 436eb8c74fb4a762b61837ee27ddbd6b5fe21334.
Unable to use splice on newer kernels due to 36e2c7421f02 ("fs: don't
allow splice read/write without explicit ops"). So revert back to plain
old read/write.

Signed-off-by: Rashmica Gupta <rashmica.g at gmail.com>
---
 libpdbg/htm.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/libpdbg/htm.c b/libpdbg/htm.c
index 0d755dd..43cef84 100644
--- a/libpdbg/htm.c
+++ b/libpdbg/htm.c
@@ -966,39 +966,41 @@ static int do_htm_status(struct htm *htm)
 	return 1;
 }
 
+#define COPY_BUF_SIZE getpagesize()
 static int copy_file(int output, int input, uint64_t size)
 {
+	char *buf;
 	size_t r;
-	int pipefd[2];
-	int rc = -1;
 
-	if (pipe(pipefd)) {
-		perror("pipe");
-		exit(1);
+	buf = malloc(COPY_BUF_SIZE);
+	if (!buf) {
+		PR_ERROR("Can't malloc buffer\n");
+		return -1;
 	}
 
 	while (size) {
-		r = splice(input, 0, pipefd[1], 0, size, 0);
+		r = read(input, buf, MIN(COPY_BUF_SIZE, size));
 		if (r == -1) {
 			PR_ERROR("Failed to read\n");
 			goto out;
 		}
 		if (r == 0) {
-			PR_ERROR("Unexpect EOF\n");
+			PR_ERROR("EOF\n");
 			goto out;
 		}
 
-		if (splice(pipefd[0], 0, output, 0, r, 0) != r) {
+		if (write(output, buf, r) != r) {
 			PR_ERROR("Short write!\n");
 			goto out;
 		}
 		size -= r;
 	}
-	rc = 0;
+
+	return 0;
+
 out:
-	close(pipefd[1]);
-	close(pipefd[0]);
-	return rc;
+	free(buf);
+	return -1;
 
 }
 
-- 
2.26.2



More information about the Pdbg mailing list