Skip to contentSkip to conversation

char: open pipe in write-only mode

PATCH New [email protected] 1 participant 2 messages Aug 5, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 char: open pipe in write-only mode

From: Marc-André Lureau <[email protected]>

When not using the "path.in", "path.out", open "path" in read-only mode, as eating our own output is usually not what we want.

Related to:
https://bugzilla.redhat.com/show_bug.cgi?id=2106975

---
 chardev/char-pipe.c |  6 ++++--
 qemu-options.hx     | 15 +++++++++------
 2 files changed, 13 insertions(+), 8 deletions(-)
chardev/char-pipe.c +4 -2
index 66d3b85091..f9897a3786 100644
@@ -138,12 +138,14 @@ static void qemu_chr_open_pipe(Chardev *chr,
     if (fd_in < 0 || fd_out < 0) {
         if (fd_in >= 0) {
             close(fd_in);
+            fd_in = -1;
         }
         if (fd_out >= 0) {
             close(fd_out);
+            fd_out = -1;
         }
-        TFR(fd_in = fd_out = qemu_open_old(filename, O_RDWR | O_BINARY));
-        if (fd_in < 0) {
+        TFR(fd_out = qemu_open_old(filename, O_WRONLY | O_BINARY));
+        if (fd_out < 0) {
             error_setg_file_open(errp, errno, filename);
             return;
         }
qemu-options.hx +9 -6
index 3f23a42fa8..ec99a6db48 100644
@@ -3514,18 +3514,21 @@ The available backends are:
     ``path`` is required.
 
 ``-chardev pipe,id=id,path=path``
-    Create a two-way connection to the guest. The behaviour differs
+    Create a one-way or two-way stream. The behaviour differs
     slightly between Windows hosts and other hosts:
 
-    On Windows, a single duplex pipe will be created at
+    On Windows, a full duplex pipe will be created at
     ``\\.pipe\path``.
 
-    On other hosts, 2 pipes will be created called ``path.in`` and
+    On other hosts, 2 paths will be opened called ``path.in`` and
     ``path.out``. Data written to ``path.in`` will be received by the
-    guest. Data written by the guest can be read from ``path.out``. QEMU
-    will not create these fifos, and requires them to be present.
+    guest. Data written by the guest can be read from ``path.out``.
+    QEMU will not create these fifos, and requires them to be present.
 
-    ``path`` forms part of the pipe path as described above. ``path`` is
+    If ``path.in`` or ``path.out`` are missing, QEMU will open
+    ``path`` for an output-only stream.
+
+    ``path`` forms part of the paths as described above. ``path`` is
     required.
 
 ``-chardev console,id=id``
Signature · 1 line
2.37.1
#1 lore raw

PATCH 2/2 char: open unidirectional in/out pipes with one-way mode

From: Marc-André Lureau <[email protected]>

This is how those paths are meant to be used.

---
 chardev/char-pipe.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
chardev/char-pipe.c +2 -2
index f9897a3786..3759558d81 100644
@@ -131,8 +131,8 @@ static void qemu_chr_open_pipe(Chardev *chr,
 
     filename_in = g_strdup_printf("%s.in", filename);
     filename_out = g_strdup_printf("%s.out", filename);
-    TFR(fd_in = qemu_open_old(filename_in, O_RDWR | O_BINARY));
-    TFR(fd_out = qemu_open_old(filename_out, O_RDWR | O_BINARY));
+    TFR(fd_in = qemu_open_old(filename_in, O_RDONLY | O_BINARY));
+    TFR(fd_out = qemu_open_old(filename_out, O_WRONLY | O_BINARY));
     g_free(filename_in);
     g_free(filename_out);
     if (fd_in < 0 || fd_out < 0) {
Signature · 1 line
2.37.1