On Mon, Oct 13, 2025 at 5:40 PM Vladimir Sementsov-Ogievskiy
<[email protected]> wrote:
>
> Absent filename and necessity to send CHR_EVENT_OPENED are artifacts
> of .open(). Handle them in qemu_char_open().
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]>

Reviewed-by: Marc-André Lureau <[email protected]>


> ---
>  chardev/char.c | 23 ++++++++++++-----------
>  1 file changed, 12 insertions(+), 11 deletions(-)
>
> diff --git a/chardev/char.c b/chardev/char.c
> index 64ec60c0f2..6498d53daa 100644
> --- a/chardev/char.c
> +++ b/chardev/char.c
> @@ -247,18 +247,27 @@ int qemu_chr_add_client(Chardev *s, int fd)
>  }
>
>  static bool qemu_char_open(Chardev *chr, ChardevBackend *backend,
> -                           bool *be_opened, Error **errp)
> +                           const char *default_filename, Error **errp)
>  {
>      ERRP_GUARD();
>      ChardevClass *cc = CHARDEV_GET_CLASS(chr);
> +    bool be_opened = true;
>
>      if (cc->open) {
> -        cc->open(chr, backend, be_opened, errp);
> +        cc->open(chr, backend, &be_opened, errp);
>          if (*errp) {
>              return false;
>          }
>      }
>
> +    if (!chr->filename) {
> +        chr->filename = g_strdup(default_filename);
> +    }
> +
> +    if (be_opened) {
> +        qemu_chr_be_event(chr, CHR_EVENT_OPENED);
> +    }
> +
>      return true;
>  }
>
> @@ -1021,7 +1030,6 @@ static Chardev *chardev_new(const char *id, const char 
> *typename,
>      Object *obj;
>      Chardev *chr = NULL;
>      Error *local_err = NULL;
> -    bool be_opened = true;
>
>      assert(g_str_has_prefix(typename, "chardev-"));
>      assert(id);
> @@ -1036,17 +1044,10 @@ static Chardev *chardev_new(const char *id, const 
> char *typename,
>          goto fail;
>      }
>
> -    if (!qemu_char_open(chr, backend, &be_opened, &local_err)) {
> +    if (!qemu_char_open(chr, backend, typename + 8, &local_err)) {
>          goto fail;
>      }
>
> -    if (!chr->filename) {
> -        chr->filename = g_strdup(typename + 8);
> -    }
> -    if (be_opened) {
> -        qemu_chr_be_event(chr, CHR_EVENT_OPENED);
> -    }
> -
>      return chr;
>
>  fail:
> --
> 2.48.1
>
>


--
Marc-André Lureau

Reply via email to