* [Qemu-devel] Unidirectional pipe support
@ 2006-12-13 18:39 Ed Swierk
0 siblings, 0 replies; only message in thread
From: Ed Swierk @ 2006-12-13 18:39 UTC (permalink / raw)
To: qemu-devel
[-- 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);
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2006-12-13 18:39 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-13 18:39 [Qemu-devel] Unidirectional pipe support Ed Swierk
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).