From patchwork Sun Apr 10 06:50:31 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Asias He X-Patchwork-Id: 696381 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p3A6pqFn010122 for ; Sun, 10 Apr 2011 06:51:53 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752340Ab1DJGvm (ORCPT ); Sun, 10 Apr 2011 02:51:42 -0400 Received: from mail-pv0-f174.google.com ([74.125.83.174]:47269 "EHLO mail-pv0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751733Ab1DJGvl (ORCPT ); Sun, 10 Apr 2011 02:51:41 -0400 Received: by pvg12 with SMTP id 12so1674505pvg.19 for ; Sat, 09 Apr 2011 23:51:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer; bh=wMhdWjqVd5ML553mcIfpYq1hez8mnbyw7rj825SqTYo=; b=V5DUhRiSVEcWr1piZZD80IlL/mRRw9nQk+o//q8s+yKxa0TpgU6/sueEbJchPRqH3Y rf4A4bfLPdAez9yEfN45DSWJbJ5eseYbWVzK8+tfWFxjhi8hkW0EGks4tN7GOrmtbI39 1fIkilgcqJUnSdhCs/vD2vCMiUIcyAKv9Oc4c= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=DqqYutBGEgqvWpmctoAo6jAShm0cf0FFVTEou3k4ILSMJo/8oNfk6pUgfkfK3JLWkQ 61oTmPftRUjvcsnZgJkSG2R1/IZRsBsb2inw9j00b4KVtxcUsrshjsPdkmWww01DOA/+ Jg8e8jddSZJZ1+uz+UhCkhRun0e2wtED5niOc= Received: by 10.142.250.32 with SMTP id x32mr3924703wfh.57.1302418300745; Sat, 09 Apr 2011 23:51:40 -0700 (PDT) Received: from localhost.localdomain ([202.112.128.131]) by mx.google.com with ESMTPS id p40sm6294163wfc.17.2011.04.09.23.51.37 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 09 Apr 2011 23:51:39 -0700 (PDT) From: Asias He To: Pekka Enberg , Cyrill Gorcunov , Ingo Molnar Cc: kvm@vger.kernel.org, Asias He Subject: [PATCH] kvm tools: Implement exit kvm tools on Ctrl+a+x Date: Sun, 10 Apr 2011 14:50:31 +0800 Message-Id: <1302418231-7364-1-git-send-email-asias.hejun@gmail.com> X-Mailer: git-send-email 1.7.4.1 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Sun, 10 Apr 2011 06:51:53 +0000 (UTC) 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 --- 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); }