public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kvm tools: Implement exit kvm tools on Ctrl+a+x
@ 2011-04-10  6:50 Asias He
  2011-04-10  7:09 ` Pekka Enberg
  0 siblings, 1 reply; 5+ messages in thread
From: Asias He @ 2011-04-10  6:50 UTC (permalink / raw)
  To: Pekka Enberg, Cyrill Gorcunov, Ingo Molnar; +Cc: kvm, Asias He

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] kvm tools: Implement exit kvm tools on Ctrl+a+x
  2011-04-10  6:50 [PATCH] kvm tools: Implement exit kvm tools on Ctrl+a+x Asias He
@ 2011-04-10  7:09 ` Pekka Enberg
  2011-04-10  7:13   ` Cyrill Gorcunov
  0 siblings, 1 reply; 5+ messages in thread
From: Pekka Enberg @ 2011-04-10  7:09 UTC (permalink / raw)
  To: Asias He; +Cc: Cyrill Gorcunov, Ingo Molnar, kvm

On Sun, Apr 10, 2011 at 9:50 AM, Asias He <asias.hejun@gmail.com> wrote:
> 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>

Cyrill, does this patch work for you? It doesn't do anything for me.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] kvm tools: Implement exit kvm tools on Ctrl+a+x
  2011-04-10  7:09 ` Pekka Enberg
@ 2011-04-10  7:13   ` Cyrill Gorcunov
  2011-04-10  8:16     ` Amos Kong
  0 siblings, 1 reply; 5+ messages in thread
From: Cyrill Gorcunov @ 2011-04-10  7:13 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: Asias He, Ingo Molnar, kvm

On 04/10/2011 11:09 AM, Pekka Enberg wrote:
> On Sun, Apr 10, 2011 at 9:50 AM, Asias He <asias.hejun@gmail.com> wrote:
>> 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>
> 
> Cyrill, does this patch work for you? It doesn't do anything for me.

Nope, doesn't work for me either.

-- 
    Cyrill

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] kvm tools: Implement exit kvm tools on Ctrl+a+x
  2011-04-10  7:13   ` Cyrill Gorcunov
@ 2011-04-10  8:16     ` Amos Kong
  2011-04-10  8:20       ` Pekka Enberg
  0 siblings, 1 reply; 5+ messages in thread
From: Amos Kong @ 2011-04-10  8:16 UTC (permalink / raw)
  To: Cyrill Gorcunov; +Cc: Pekka Enberg, Asias He, Ingo Molnar, kvm

On Sun, Apr 10, 2011 at 11:13:54AM +0400, Cyrill Gorcunov wrote:
> On 04/10/2011 11:09 AM, Pekka Enberg wrote:
> > On Sun, Apr 10, 2011 at 9:50 AM, Asias He <asias.hejun@gmail.com> wrote:
> >> 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>
> > 
> > Cyrill, does this patch work for you? It doesn't do anything for me.
> 
> Nope, doesn't work for me either.

This patch works for me.


It should be:
Ctrl+a 
x
------------
Not
Ctrl+a
Ctrl+x
------------
Not 
Ctrl+a+x (hit three keys at the same time)
 
Amos.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] kvm tools: Implement exit kvm tools on Ctrl+a+x
  2011-04-10  8:16     ` Amos Kong
@ 2011-04-10  8:20       ` Pekka Enberg
  0 siblings, 0 replies; 5+ messages in thread
From: Pekka Enberg @ 2011-04-10  8:20 UTC (permalink / raw)
  To: Amos Kong; +Cc: Cyrill Gorcunov, Asias He, Ingo Molnar, kvm

On Sun, Apr 10, 2011 at 11:16 AM, Amos Kong <akong@redhat.com> wrote:
> On Sun, Apr 10, 2011 at 11:13:54AM +0400, Cyrill Gorcunov wrote:
>> On 04/10/2011 11:09 AM, Pekka Enberg wrote:
>> > On Sun, Apr 10, 2011 at 9:50 AM, Asias He <asias.hejun@gmail.com> wrote:
>> >> 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>
>> >
>> > Cyrill, does this patch work for you? It doesn't do anything for me.
>>
>> Nope, doesn't work for me either.
>
> This patch works for me.
>
> It should be:
> Ctrl+a
> x

Aah, works for me too. I guess I was doing Ctrl-a + Ctlr+x
unconsciously. Thanks, I'll apply the patch!

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-04-10  8:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-10  6:50 [PATCH] kvm tools: Implement exit kvm tools on Ctrl+a+x Asias He
2011-04-10  7:09 ` Pekka Enberg
2011-04-10  7:13   ` Cyrill Gorcunov
2011-04-10  8:16     ` Amos Kong
2011-04-10  8:20       ` Pekka Enberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox