[PATCH v4 15/23] utils: Write a maximum of MAX_PIPE_WRITE_BYTES into a pipe

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

 



To avoid blocking on a write on a pipe that the receiving process
does not read from, write only MAX_PIPE_WRITE_BYTES into the pipe
so that we can serve other pipes as well.

Signed-off-by: Stefan Berger <stefanb@xxxxxxxxxxxxx>
---
 src/util/vircommand.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/util/vircommand.c b/src/util/vircommand.c
index 49347a9800..3ac51c77a8 100644
--- a/src/util/vircommand.c
+++ b/src/util/vircommand.c
@@ -86,6 +86,8 @@ struct _virCommandSendBuffer {
     size_t buflen;
     off_t offset;
 };
+/* max. number of bytes we write to pipe to avoid blocking on it */
+#define MAX_PIPE_WRITE_BYTES 1024
 
 struct _virCommand {
     int has_error; /* ENOMEM on allocation failure, -1 for anything else.  */
@@ -2251,7 +2253,7 @@ virCommandProcessIO(virCommandPtr cmd)
                 int done;
 
                 done = write(cmd->inpipe, cmd->inbuf + inoff,
-                             inlen - inoff);
+                             MIN(inlen - inoff, MAX_PIPE_WRITE_BYTES));
                 if (done < 0) {
                     if (errno == EPIPE) {
                         VIR_DEBUG("child closed stdin early, ignoring EPIPE "
-- 
2.20.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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