chardev: switch pty init to qapi

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 <kraxel@redhat.com>
This commit is contained in:
Gerd Hoffmann 2013-02-25 10:16:46 +01:00
parent dc37509769
commit e68c595866

View File

@ -1157,13 +1157,13 @@ static void pty_chr_close(struct CharDriverState *chr)
qemu_chr_be_event(chr, CHR_EVENT_CLOSED); 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; CharDriverState *chr;
PtyCharDriver *s; PtyCharDriver *s;
struct termios tty; struct termios tty;
const char *label; int master_fd, slave_fd;
int master_fd, slave_fd, len;
#if defined(__OpenBSD__) || defined(__DragonFly__) #if defined(__OpenBSD__) || defined(__DragonFly__)
char pty_name[PATH_MAX]; char pty_name[PATH_MAX];
#define q_ptsname(x) pty_name #define q_ptsname(x) pty_name
@ -1184,17 +1184,12 @@ static CharDriverState *qemu_chr_open_pty(QemuOpts *opts)
chr = g_malloc0(sizeof(CharDriverState)); chr = g_malloc0(sizeof(CharDriverState));
len = strlen(q_ptsname(master_fd)) + 5; chr->filename = g_strdup_printf("pty:%s", q_ptsname(master_fd));
chr->filename = g_malloc(len); ret->pty = g_strdup(q_ptsname(master_fd));
snprintf(chr->filename, len, "pty:%s", q_ptsname(master_fd)); ret->has_pty = true;
qemu_opt_set(opts, "path", q_ptsname(master_fd));
label = qemu_opts_id(opts); fprintf(stderr, "char device redirected to %s (label %s)\n",
fprintf(stderr, "char device redirected to %s%s%s%s\n", q_ptsname(master_fd), id);
q_ptsname(master_fd),
label ? " (label " : "",
label ? label : "",
label ? ")" : "");
s = g_malloc0(sizeof(PtyCharDriver)); s = g_malloc0(sizeof(PtyCharDriver));
chr->opaque = s; chr->opaque = s;
@ -3687,16 +3682,8 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,
break; break;
#ifdef HAVE_CHARDEV_TTY #ifdef HAVE_CHARDEV_TTY
case CHARDEV_BACKEND_KIND_PTY: case CHARDEV_BACKEND_KIND_PTY:
{ chr = qemu_chr_open_pty(id, ret);
/* 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);
break; break;
}
#endif #endif
case CHARDEV_BACKEND_KIND_NULL: case CHARDEV_BACKEND_KIND_NULL:
chr = qemu_chr_open_null(); chr = qemu_chr_open_null();
@ -3776,15 +3763,13 @@ static void register_types(void)
qemu_chr_parse_parallel); qemu_chr_parse_parallel);
register_char_driver_qapi("parport", CHARDEV_BACKEND_KIND_PARALLEL, register_char_driver_qapi("parport", CHARDEV_BACKEND_KIND_PARALLEL,
qemu_chr_parse_parallel); qemu_chr_parse_parallel);
register_char_driver_qapi("pty", CHARDEV_BACKEND_KIND_PTY, NULL);
#ifdef _WIN32 #ifdef _WIN32
register_char_driver("pipe", qemu_chr_open_win_pipe); register_char_driver("pipe", qemu_chr_open_win_pipe);
register_char_driver("console", qemu_chr_open_win_con); register_char_driver("console", qemu_chr_open_win_con);
#else #else
register_char_driver("pipe", qemu_chr_open_pipe); register_char_driver("pipe", qemu_chr_open_pipe);
#endif #endif
#ifdef HAVE_CHARDEV_TTY
register_char_driver("pty", qemu_chr_open_pty);
#endif
} }
type_init(register_types); type_init(register_types);