]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
utils: Mark inpipe as non-blocking
authorStefan Berger <stefanb@linux.vnet.ibm.com>
Thu, 25 Jul 2019 18:22:08 +0000 (14:22 -0400)
committerDaniel P. Berrangé <berrange@redhat.com>
Fri, 26 Jul 2019 09:30:54 +0000 (10:30 +0100)
Mark a virCommand's inpipe (write-end of pipe) as non-blocking so that it
will never block when we were to try to write too many bytes to it while
it doesn't have the capacity to hold them.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
src/util/vircommand.c

index 94b2ebc8aa54f5e4401c3b13649b1d7436703121..a3a5780d2911d362fa39243da57a11b50e96fd8c 100644 (file)
@@ -2538,6 +2538,19 @@ virCommandRunAsync(virCommandPtr cmd, pid_t *pid)
         }
         cmd->infd = infd[0];
         cmd->inpipe = infd[1];
+#if defined (F_SETFL)
+        if (fcntl(cmd->inpipe, F_SETFL, O_NONBLOCK) < 0) {
+            virReportSystemError(errno, "%s",
+                                 _("fcntl failed to set O_NONBLOCK"));
+            cmd->has_error = -1;
+            ret = -1;
+            goto cleanup;
+        }
+#else /* !defined(F_SETFL) */
+        cmd->has_error = ENOTSUP;
+        ret = -1;
+        goto cleanup;
+#endif
     } else if ((cmd->inbuf && cmd->infd == -1) ||
                (cmd->outbuf && cmd->outfdptr != &cmd->outfd) ||
                (cmd->errbuf && cmd->errfdptr != &cmd->errfd)) {