From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Filip Hejsek <filip.hejsek@gmail.com>
Cc: qemu-devel@nongnu.org,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>
Subject: Re: [PATCH v2 2/2] io: report a warning when a file channel is created from a stdio fd
Date: Thu, 15 Oct 2026 09:07:30 +0100 [thread overview]
Message-ID: <atCJwox47RUEkD1I@redhat.com> (raw)
In-Reply-To: <20261015-fix-stdio-close-v2-2-0f01e6580e24@gmail.com>
On Thu, Oct 15, 2026 at 03:58:25AM +0200, Filip Hejsek wrote:
> A channel closes its fd when the last reference to it is dropped.
> Closing stdio fds is typically unwanted, so warn when they are passed to
> qio_channel_file_new_fd().
>
> Signed-off-by: Filip Hejsek <filip.hejsek@gmail.com>
> ---
> io/channel-file.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/io/channel-file.c b/io/channel-file.c
> index 5cef75a67c..4c9da6619b 100644
> --- a/io/channel-file.c
> +++ b/io/channel-file.c
> @@ -23,6 +23,7 @@
> #include "io/channel-util.h"
> #include "io/channel-watch.h"
> #include "qapi/error.h"
> +#include "qemu/error-report.h"
> #include "qemu/module.h"
> #include "qemu/sockets.h"
> #include "trace.h"
> @@ -32,6 +33,11 @@ qio_channel_file_new_fd(int fd)
> {
> QIOChannelFile *ioc;
>
> + if (fd <= STDERR_FILENO) {
> + warn_report("potential bug: creating a channel from stdio fd %d; "
> + "the fd will be closed when the channel is destroyed", fd);
> + }
> +
> ioc = QIO_CHANNEL_FILE(object_new(TYPE_QIO_CHANNEL_FILE));
>
> ioc->fd = fd;
Can we also update the API docs for qio_channel_file_new_fd, to
say
@fd must not point to stdin/stdout/stderr, since the FD
will be closed by the channel on destruction. If requiring
a channel to wrap stdio, use qio_channel_file_new_dupfd()
instead.
With regards,
Daniel
--
|: https://berrange.com ~~ https://hachyderm.io/@berrange :|
|: https://libvirt.org ~~ https://entangle-photo.org :|
|: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
prev parent reply other threads:[~2026-10-15 8:07 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 ` [PATCH v2 1/2] char-stdio: avoid closing " Filip Hejsek
2026-10-15 11:47 ` 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é [this message]
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=atCJwox47RUEkD1I@redhat.com \
--to=berrange@redhat.com \
--cc=filip.hejsek@gmail.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.