Commit aa523ea83d for qemu.org

commit aa523ea83d68f498f081c9a78e02f80b63f4ea7c
Author: Filip Hejsek <filip.hejsek@gmail.com>
Date:   Sat Oct 17 01:09:08 2026 +0200

    char-stdio: avoid closing stdio fds

    Use a duplicate of stdin and stdout fds to avoid closing the standard
    descriptors when the stdio chardev is destroyed.

    Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
    Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
    Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
    Message-ID: <20261017-fix-stdio-close-v3-1-cfff0122a2a4@gmail.com>

diff --git a/chardev/char-stdio.c b/chardev/char-stdio.c
index f63bf413c7..16b49fd924 100644
--- a/chardev/char-stdio.c
+++ b/chardev/char-stdio.c
@@ -114,6 +114,7 @@ static bool stdio_chr_open(Chardev *chr, ChardevBackend *backend, Error **errp)
     StdioChardev *s = STDIO_CHARDEV(chr);
     ChardevStdio *opts = backend->u.stdio.data;
     struct sigaction act;
+    int fd_in, fd_out;

     if (is_daemonized()) {
         error_setg(errp, "cannot use stdio with -daemonize");
@@ -133,7 +134,20 @@ static bool stdio_chr_open(Chardev *chr, ChardevBackend *backend, Error **errp)
         return false;
     }

-    if (!qemu_chr_open_fd(chr, 0, 1, errp)) {
+    fd_in = qemu_dup(0);
+    if (fd_in < 0) {
+        error_setg_errno(errp, errno, "Failed to dup stdin fd");
+        return false;
+    }
+    fd_out = qemu_dup(1);
+    if (fd_out < 0) {
+        error_setg_errno(errp, errno, "Failed to dup stdout fd");
+        qemu_close(fd_in);
+        return false;
+    }
+    if (!qemu_chr_open_fd(chr, fd_in, fd_out, errp)) {
+        qemu_close(fd_in);
+        qemu_close(fd_out);
         return false;
     }