This patch switches over the pty chardev initialization to the new qapi code path.
Bonus: Taking QemuOpts out of the loop allows some nice cleanups along the way. Signed-off-by: Gerd Hoffmann <kra...@redhat.com> --- qemu-char.c | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/qemu-char.c b/qemu-char.c index 2832e48..2652b86 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -971,13 +971,13 @@ static void pty_chr_close(struct CharDriverState *chr) qemu_chr_be_event(chr, CHR_EVENT_CLOSED); } -static CharDriverState *qemu_chr_open_pty(QemuOpts *opts) +static CharDriverState *qemu_chr_open_pty(const char *id, + ChardevReturn *ret) { CharDriverState *chr; PtyCharDriver *s; struct termios tty; - const char *label; - int master_fd, slave_fd, len; + int master_fd, slave_fd; #if defined(__OpenBSD__) || defined(__DragonFly__) char pty_name[PATH_MAX]; #define q_ptsname(x) pty_name @@ -998,17 +998,12 @@ static CharDriverState *qemu_chr_open_pty(QemuOpts *opts) chr = g_malloc0(sizeof(CharDriverState)); - len = strlen(q_ptsname(master_fd)) + 5; - chr->filename = g_malloc(len); - snprintf(chr->filename, len, "pty:%s", q_ptsname(master_fd)); - qemu_opt_set(opts, "path", q_ptsname(master_fd)); + chr->filename = g_strdup_printf("pty:%s", q_ptsname(master_fd)); + ret->pty = g_strdup(q_ptsname(master_fd)); + ret->has_pty = true; - label = qemu_opts_id(opts); - fprintf(stderr, "char device redirected to %s%s%s%s\n", - q_ptsname(master_fd), - label ? " (label " : "", - label ? label : "", - label ? ")" : ""); + fprintf(stderr, "char device redirected to %s (label %s)\n", + q_ptsname(master_fd), id); s = g_malloc0(sizeof(PtyCharDriver)); chr->opaque = s; @@ -2989,6 +2984,7 @@ static const struct { .parse = qemu_chr_parse_parallel }, { .name = "parport", .kind = CHARDEV_BACKEND_KIND_PARALLEL, .parse = qemu_chr_parse_parallel }, + { .name = "pty", .kind = CHARDEV_BACKEND_KIND_PTY }, #ifdef _WIN32 { .name = "pipe", .open = qemu_chr_open_win_pipe }, { .name = "console", .open = qemu_chr_open_win_con }, @@ -2996,9 +2992,6 @@ static const struct { { .name = "pipe", .open = qemu_chr_open_pipe }, #endif { .name = "braille", .kind = CHARDEV_BACKEND_KIND_BRAILLE }, -#ifdef HAVE_CHARDEV_TTY - { .name = "pty", .open = qemu_chr_open_pty }, -#endif #ifdef CONFIG_SPICE { .name = "spicevmc", .open = qemu_chr_open_spice }, #if SPICE_SERVER_VERSION >= 0x000c02 @@ -3444,16 +3437,8 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend, break; #ifdef HAVE_CHARDEV_TTY case CHARDEV_BACKEND_KIND_PTY: - { - /* qemu_chr_open_pty sets "path" in opts */ - QemuOpts *opts; - opts = qemu_opts_create_nofail(qemu_find_opts("chardev")); - chr = qemu_chr_open_pty(opts); - ret->pty = g_strdup(qemu_opt_get(opts, "path")); - ret->has_pty = true; - qemu_opts_del(opts); + chr = qemu_chr_open_pty(id, ret); break; - } #endif case CHARDEV_BACKEND_KIND_NULL: chr = qemu_chr_open_null(); -- 1.7.9.7