[libvirt RFCv4 04/20] runio: add arguments to extend use beyond just stdin and stdout

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



add arguments to runio to allow read/write from/to arbitrary
file descriptors, as opposed to just stdin and stdout.

Signed-off-by: Claudio Fontana <cfontana@xxxxxxx>
---
 src/util/iohelper.c |  2 +-
 src/util/runio.c    | 10 +++++-----
 src/util/runio.h    | 17 ++++++++++++++++-
 3 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/src/util/iohelper.c b/src/util/iohelper.c
index 5a0098542e..93674c1e2f 100644
--- a/src/util/iohelper.c
+++ b/src/util/iohelper.c
@@ -96,7 +96,7 @@ main(int argc, char **argv)
         usage(EXIT_FAILURE);
     }
 
-    if (fd < 0 || runIO(path, fd, oflags) < 0)
+    if (fd < 0 || runIO(path, fd, oflags, STDIN_FILENO, STDOUT_FILENO) < 0)
         goto error;
 
     return 0;
diff --git a/src/util/runio.c b/src/util/runio.c
index a7b902af7e..f42acddae9 100644
--- a/src/util/runio.c
+++ b/src/util/runio.c
@@ -134,7 +134,7 @@ runIOCopy(const struct runIOParams p)
 
 
 off_t
-runIO(const char *path, int fd, int oflags)
+runIO(const char *path, int fd, int oflags, int in_fd, int out_fd)
 {
     int ret = -1;
     off_t total = 0;
@@ -155,13 +155,13 @@ runIO(const char *path, int fd, int oflags)
         p.isWrite = false;
         p.fdin = fd;
         p.fdinname = path;
-        p.fdout = STDOUT_FILENO;
-        p.fdoutname = "stdout";
+        p.fdout = out_fd;
+        p.fdoutname = "output";
         break;
     case O_WRONLY:
         p.isWrite = true;
-        p.fdin = STDIN_FILENO;
-        p.fdinname = "stdin";
+        p.fdin = in_fd;
+        p.fdinname = "input";
         p.fdout = fd;
         p.fdoutname = path;
         break;
diff --git a/src/util/runio.h b/src/util/runio.h
index beb58606c9..66df588881 100644
--- a/src/util/runio.h
+++ b/src/util/runio.h
@@ -20,4 +20,19 @@
 
 #pragma once
 
-off_t runIO(const char *path, int fd, int oflags);
+/*
+ * runIO: copy unidirectionally all data to/from a file descriptor.
+ *
+ * @path: the pathname corresponding to FD.
+ * @fd: the file descriptor to read from or write to.
+ * @oflags: the file status flags of FD.
+ *
+ * If the oflags indicate O_RDONLY, then the direction will be from FD,
+ * and @out_fd indicates the file to write to.
+ *
+ * If the oflags indicate O_WRONLY, then the direction will be to FD,
+ * and @in_fd indicates the file to read from.
+ *
+ * Returns the number of bytes transferred, or < 0 on error.
+ */
+off_t runIO(const char *path, int fd, int oflags, int in_fd, int out_fd);
-- 
2.34.1





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux