From: Asias He <asias.hejun@gmail.com>
To: Pekka Enberg <penberg@kernel.org>,
Cyrill Gorcunov <gorcunov@gmail.com>, Ingo Molnar <mingo@elte.hu>
Cc: kvm@vger.kernel.org, Asias He <asias.hejun@gmail.com>
Subject: [PATCH] kvm tools: Implement exit kvm tools on Ctrl+a+x
Date: Sun, 10 Apr 2011 14:50:31 +0800 [thread overview]
Message-ID: <1302418231-7364-1-git-send-email-asias.hejun@gmail.com> (raw)
This patch makes Ctrl+a escape key. Ctrl+a+x will terminate kvm tools.
It works for both serial and virtio console.
If you want to input Ctrl+a to guest, type Ctrl+a twice.
Signed-off-by: Asias He <asias.hejun@gmail.com>
---
tools/kvm/term.c | 41 ++++++++++++++++++++++++++++++++++++-----
1 files changed, 36 insertions(+), 5 deletions(-)
diff --git a/tools/kvm/term.c b/tools/kvm/term.c
index 9b235d0..d862998 100644
--- a/tools/kvm/term.c
+++ b/tools/kvm/term.c
@@ -9,9 +9,12 @@
#include "kvm/term.h"
#include "kvm/util.h"
-static struct termios orig_term;
+static struct termios orig_term;
-int active_console = CONSOLE_8250;
+int term_escape_char = 0x01; /* ctrl-a is used for escape */
+bool term_got_escape = false;
+
+int active_console = CONSOLE_8250;
int term_getc(int who)
{
@@ -22,6 +25,24 @@ int term_getc(int who)
if (read_in_full(STDIN_FILENO, &c, 1) < 0)
return -1;
+
+ c &= 0xff;
+
+ if (term_got_escape) {
+ term_got_escape = false;
+ if (c == 'x') {
+ printf("\nKVM TOOLS: Terminated\n");
+ exit(1);
+ }
+ if (c == term_escape_char)
+ return c;
+ }
+
+ if (c == term_escape_char) {
+ term_got_escape = true;
+ return -1;
+ }
+
return c;
}
@@ -39,16 +60,26 @@ int term_putc(int who, char *addr, int cnt)
int term_getc_iov(int who, struct iovec *iov, int iovcnt)
{
+ int c;
+
if (who != active_console)
- return -1;
+ return 0;
+
+ c = term_getc(who);
- return readv(STDIN_FILENO, iov, iovcnt);
+ if (c < 0)
+ return 0;
+
+ *((int *)iov[0].iov_base) = c;
+ iov[0].iov_len = sizeof(int);
+
+ return sizeof(int);
}
int term_putc_iov(int who, struct iovec *iov, int iovcnt)
{
if (who != active_console)
- return -1;
+ return 0;
return writev(STDOUT_FILENO, iov, iovcnt);
}
--
1.7.4.1
next reply other threads:[~2011-04-10 6:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-10 6:50 Asias He [this message]
2011-04-10 7:09 ` [PATCH] kvm tools: Implement exit kvm tools on Ctrl+a+x Pekka Enberg
2011-04-10 7:13 ` Cyrill Gorcunov
2011-04-10 8:16 ` Amos Kong
2011-04-10 8:20 ` Pekka Enberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1302418231-7364-1-git-send-email-asias.hejun@gmail.com \
--to=asias.hejun@gmail.com \
--cc=gorcunov@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=penberg@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox