From: "Ed Swierk" <eswierk@arastra.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] Unidirectional pipe support
Date: Wed, 13 Dec 2006 10:39:45 -0800 [thread overview]
Message-ID: <c1bf1cf0612131039r245b55edma75f12cc0a860aee@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 953 bytes --]
qemu allows redirecting the monitor to a named pipe (fifo): if you
specify "-monitor pipe:/my/fifo", it opens "/my/fifo" and uses it for
communication in both directions.
Unfortunately pipes are unidirectional on Linux. The pipe(7) man page
says: "Portability notes: On some systems (but not Linux), pipes are
bidirectional: data can be transmitted in both directions between the
pipe ends. According to POSIX.1-2001, pipes only need to be
unidirectional. Portable applications should avoid reliance on
bidirectional pipe semantics."
When qemu writes into the pipe, it immediately reads back what it just
wrote and treats it as a monitor command, endlessly breathing its own
exhaust.
The attached patch changes qemu to first try opening a pair of pipes,
"/my/fifo.in" and "/my/fifo.out", and uses each to communicate in a
single direction. If either file cannot be opened, it reverts to the
current behavior, using "/my/fifo" bidirectionally.
--Ed
[-- Attachment #2: qemu-pipe-pair.patch --]
[-- Type: text/x-patch, Size: 889 bytes --]
Index: qemu-0.8.2/vl.c
===================================================================
--- qemu-0.8.2.orig/vl.c
+++ qemu-0.8.2/vl.c
@@ -1285,12 +1285,19 @@ CharDriverState *qemu_chr_open_file_out(
CharDriverState *qemu_chr_open_pipe(const char *filename)
{
- int fd;
+ int fd_in, fd_out;
+ char filename_in[256], filename_out[256];
- fd = open(filename, O_RDWR | O_BINARY);
- if (fd < 0)
- return NULL;
- return qemu_chr_open_fd(fd, fd);
+ snprintf(filename_in, 256, "%s.in", filename);
+ snprintf(filename_out, 256, "%s.out", filename);
+ fd_in = open(filename_in, O_RDWR | O_BINARY);
+ fd_out = open(filename_out, O_RDWR | O_BINARY);
+ if (fd_in < 0 || fd_out < 0) {
+ fd_in = fd_out = open(filename, O_RDWR | O_BINARY);
+ if (fd_in < 0)
+ return NULL;
+ }
+ return qemu_chr_open_fd(fd_in, fd_out);
}
reply other threads:[~2006-12-13 18:39 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c1bf1cf0612131039r245b55edma75f12cc0a860aee@mail.gmail.com \
--to=eswierk@arastra.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).