From: Filip Hejsek <filip.hejsek@gmail.com>
To: qemu-devel@nongnu.org
Cc: "Daniel P. Berrangé" <berrange@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>
Subject: [PATCH v2 1/2] char-stdio: avoid closing stdio fds
Date: Thu, 15 Oct 2026 03:58:24 +0200 [thread overview]
Message-ID: <20261015-fix-stdio-close-v2-1-0f01e6580e24@gmail.com> (raw)
In-Reply-To: <20261015-fix-stdio-close-v2-0-0f01e6580e24@gmail.com>
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>
---
chardev/char-stdio.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/chardev/char-stdio.c b/chardev/char-stdio.c
index fe1cbb2d88..19860e960d 100644
--- a/chardev/char-stdio.c
+++ b/chardev/char-stdio.c
@@ -89,6 +89,7 @@ static bool stdio_chr_open(Chardev *chr, ChardevBackend *backend, Error **errp)
{
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");
@@ -108,7 +109,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;
}
--
2.56.0
next prev parent reply other threads:[~2026-10-15 2:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-15 1:58 [PATCH v2 0/2] io: make sure we don't close stdio fds Filip Hejsek
2026-10-15 1:58 ` Filip Hejsek [this message]
2026-10-15 11:47 ` [PATCH v2 1/2] char-stdio: avoid closing " Marc-André Lureau
2026-10-15 1:58 ` [PATCH v2 2/2] io: report a warning when a file channel is created from a stdio fd Filip Hejsek
2026-10-15 8:07 ` Daniel P. Berrangé
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=20261015-fix-stdio-close-v2-1-0f01e6580e24@gmail.com \
--to=filip.hejsek@gmail.com \
--cc=berrange@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.