Skip to content

Commit

Permalink
qemu-char: Permit only a single "stdio" character device
Browse files Browse the repository at this point in the history
When more than one is used, the terminal settings aren't restored
correctly on exit.  Fixable.  However, such usage makes no sense,
because the users race for input, so outlaw it instead.

If you want to connect multiple things to stdio, use the mux
chardev.

Signed-off-by: Li Liu <john.liuli@huawei.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
  • Loading branch information
Li Liu authored and Michael Tokarev committed Sep 20, 2014
1 parent 07e2863 commit c88930a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion qemu-char.c
Expand Up @@ -1017,6 +1017,7 @@ static CharDriverState *qemu_chr_open_pipe(ChardevHostdev *opts)
/* init terminal so that we can grab keys */
static struct termios oldtty;
static int old_fd0_flags;
static bool stdio_in_use;
static bool stdio_allow_signal;

static void term_exit(void)
Expand Down Expand Up @@ -1060,8 +1061,15 @@ static CharDriverState *qemu_chr_open_stdio(ChardevStdio *opts)
error_report("cannot use stdio with -daemonize");
return NULL;
}

if (stdio_in_use) {
error_report("cannot use stdio by multiple character devices");
exit(1);
}

stdio_in_use = true;
old_fd0_flags = fcntl(0, F_GETFL);
tcgetattr (0, &oldtty);
tcgetattr(0, &oldtty);
qemu_set_nonblock(0);
atexit(term_exit);

Expand Down

0 comments on commit c88930a

Please sign in to comment.