> 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 <[email protected]>
> Message-ID: <[email protected]>
>
> diff --git a/io/channel-file.c b/io/channel-file.c
> index 5cef75a67c62..98ed8a973e76 100644
> --- a/io/channel-file.c
> +++ b/io/channel-file.c
> @@ -19,6 +19,7 @@
> */
>
> #include "qemu/osdep.h"
> +#include "qemu/error-report.h"
place it below, with other qemu/ headers to preserve alphabetical ordering
> #include "io/channel-file.h"
> #include "io/channel-util.h"
> #include "io/channel-watch.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;
Reviewed-by: Marc-André Lureau <[email protected]>
--
Marc-André Lureau <[email protected]>