From 7f940d74972485d23d8d0bc04a72e5b689076a8f Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Thu, 25 Jul 2019 14:22:08 -0400 Subject: [PATCH] utils: Mark inpipe as non-blocking MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Daniel P. Berrangé --- src/util/vircommand.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 94b2ebc8aa..a3a5780d29 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -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)) { -- 2.47.2