On Thu, Oct 15, 2026 at 5:59 AM Filip Hejsek <[email protected]> wrote: > > 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 <[email protected]>
Reviewed-by: Marc-André Lureau <[email protected]> > --- > 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 >
