To avoid blocking on a write on a pipe that the receiving process
does not read from, write only MAX_PIPE_FEED_BYTES into the pipe
so that we can serve other pipes as well.
Signed-off-by: Stefan Berger <stefanb(a)linux.ibm.com>
---
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 898ee0df45..0e367eeeab 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_FEED_BYTES 1024
struct _virCommand {
int has_error; /* ENOMEM on allocation failure, -1 for anything else. */
@@ -2237,7 +2239,7 @@ virCommandProcessIO(virCommandPtr cmd)
int done;
done = write(cmd->inpipe, cmd->inbuf + inoff,
- inlen - inoff);
+ MIN(inlen - inoff, MAX_PIPE_FEED_BYTES));
if (done < 0) {
if (errno == EPIPE) {
VIR_DEBUG("child closed stdin early, ignoring EPIPE "
--
2.20.1