Skip to content

Commit

Permalink
qemu-char: Inherit ptys and improve output from -serial pty
Browse files Browse the repository at this point in the history
Changes since V1:
  - Avoid crashing since qemu_opts_id() may return null on some
    systems according to Markus's suggestion.

When controlling a qemu instance from another program, it's
hard to know which serial port or monitor device is redirected
to which pty. With more than one device using "pty" a lot of
guesswork is involved.

$ ./x86_64-softmmu/qemu-system-x86_64 -serial pty -serial pty -monitor pty
char device redirected to /dev/pts/5
char device redirected to /dev/pts/6
char device redirected to /dev/pts/7

Although we can find out what everything else is connected to
by the "info chardev" with "-monitor stdio" in the command line,
It'd be very useful to be able to have qemu inherit pseudo-tty
file descriptors so they could just be specified on the command
line like:

$ ./x86_64-softmmu/qemu-system-x86_64 -serial pty -serial pty -monitor pty
char device compat_monitor0 redirected to /dev/pts/5
char device serial0 redirected to /dev/pts/6
char device serial1 redirected to /dev/pts/7

Referred link: https://bugs.launchpad.net/qemu/+bug/938552

Signed-off-by: Lei Li <lilei@linux.vnet.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
  • Loading branch information
leilihh authored and Anthony Liguori committed Dec 23, 2012
1 parent 36f25d2 commit 5865021
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion qemu-char.c
Expand Up @@ -980,6 +980,7 @@ static CharDriverState *qemu_chr_open_pty(QemuOpts *opts)
CharDriverState *chr;
PtyCharDriver *s;
struct termios tty;
const char *label;
int master_fd, slave_fd, len;
#if defined(__OpenBSD__) || defined(__DragonFly__)
char pty_name[PATH_MAX];
Expand All @@ -1005,7 +1006,12 @@ static CharDriverState *qemu_chr_open_pty(QemuOpts *opts)
chr->filename = g_malloc(len);
snprintf(chr->filename, len, "pty:%s", q_ptsname(master_fd));
qemu_opt_set(opts, "path", q_ptsname(master_fd));
fprintf(stderr, "char device redirected to %s\n", q_ptsname(master_fd));

label = qemu_opts_id(opts);
fprintf(stderr, "char device%s%s redirected to %s\n",
label ? " " : "",
label ?: "",
q_ptsname(master_fd));

s = g_malloc0(sizeof(PtyCharDriver));
chr->opaque = s;
Expand Down

0 comments on commit 5865021

Please sign in to comment.