From patchwork Wed Sep 5 08:31:48 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 1406551 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id D511A40220 for ; Wed, 5 Sep 2012 08:33:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758110Ab2IEIdM (ORCPT ); Wed, 5 Sep 2012 04:33:12 -0400 Received: from mail-wg0-f44.google.com ([74.125.82.44]:56730 "EHLO mail-wg0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754697Ab2IEIdH (ORCPT ); Wed, 5 Sep 2012 04:33:07 -0400 Received: by mail-wg0-f44.google.com with SMTP id dr13so389214wgb.1 for ; Wed, 05 Sep 2012 01:33:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=GxSHok/LZZ2XCv9DLvBY5MVSyHXmAeBVEQ40qiv8zxg=; b=a+GVtLcp2hxNW6Z7rfL/UMv4sbGAiJ8gKji1KPM69QJ368zZo6m0pGBB7xUpKNYb3s U3bixVB+L4ZdhPFs65iQEv6p6sRfd2YfBvd3n8TPMS6wzCi6snW5pLVBNWlADwBf3qtW /fxloXVduJFVgg54pVUTvp8yyhg82KW4ThLo0uLyaoXJhleWrw3TDbbwS3U4I9VV40T/ 9x7fJiQa2HhnegZnlxKyNdHP/Z+sYJNAxAbRoIuluvpYJBlHL8M9reS5ckhihK6/lyv6 T97P1DTOa0ej7AwVDQZ6x/PIRuF7H7HfgHCAD85VB0NWfFNfnRD+1izl0NlKOCVgOW7J QsbQ== Received: by 10.180.100.133 with SMTP id ey5mr36434896wib.4.1346833986576; Wed, 05 Sep 2012 01:33:06 -0700 (PDT) Received: from lappy.capriciverd.com (20.Red-80-59-140.staticIP.rima-tde.net. [80.59.140.20]) by mx.google.com with ESMTPS id q4sm27971068wix.9.2012.09.05.01.32.52 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 05 Sep 2012 01:33:05 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: asias.hejun@gmail.com, mingo@elte.hu, gorcunov@openvz.org, kvm@vger.kernel.org, Sasha Levin Subject: [PATCH 14/33] kvm tools: improve term init/exit functions Date: Wed, 5 Sep 2012 10:31:48 +0200 Message-Id: <1346833927-15740-15-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.12 In-Reply-To: <1346833927-15740-1-git-send-email-levinsasha928@gmail.com> References: <1346833927-15740-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Make the init and exit functions of the term code similar to the rest of the code. Also move in the pty parser into the term code out of builtin-run. Signed-off-by: Sasha Levin --- tools/kvm/builtin-run.c | 19 +++++++++---------- tools/kvm/include/kvm/term.h | 6 +++++- tools/kvm/term.c | 28 ++++++++++++++++++++++++---- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c index 569c934..b4da06e 100644 --- a/tools/kvm/builtin-run.c +++ b/tools/kvm/builtin-run.c @@ -146,15 +146,6 @@ static int virtio_9p_rootdir_parser(const struct option *opt, const char *arg, i return 0; } -static int tty_parser(const struct option *opt, const char *arg, int unset) -{ - int tty = atoi(arg); - - term_set_tty(tty); - - return 0; -} - static inline void str_to_mac(const char *str, char *mac) { sscanf(str, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", @@ -988,7 +979,11 @@ static int kvm_cmd_run_init(int argc, const char **argv) if (!kvm->cfg.script) kvm->cfg.script = DEFAULT_SCRIPT; - term_init(); + r = term_init(kvm); + if (r < 0) { + pr_err("term_init() failed with error %d\n", r); + goto fail; + } if (!kvm->cfg.guest_name) { if (kvm->cfg.custom_rootfs) { @@ -1302,6 +1297,10 @@ static void kvm_cmd_run_exit(int guest_ret) if (r < 0) pr_warning("pci__exit() failed with error %d\n", r); + r = term_exit(kvm); + if (r < 0) + pr_warning("pci__exit() failed with error %d\n", r); + r = kvm__exit(kvm); if (r < 0) pr_warning("pci__exit() failed with error %d\n", r); diff --git a/tools/kvm/include/kvm/term.h b/tools/kvm/include/kvm/term.h index 33d96ce..493ce39 100644 --- a/tools/kvm/include/kvm/term.h +++ b/tools/kvm/include/kvm/term.h @@ -1,6 +1,8 @@ #ifndef KVM__TERM_H #define KVM__TERM_H +#include "kvm/kvm.h" + #include #include @@ -15,6 +17,8 @@ int term_getc(int term); bool term_readable(int term); void term_set_tty(int term); -void term_init(void); +int term_init(struct kvm *kvm); +int term_exit(struct kvm *kvm); +int tty_parser(const struct option *opt, const char *arg, int unset); #endif /* KVM__TERM_H */ diff --git a/tools/kvm/term.c b/tools/kvm/term.c index fb7963e..66f4804 100644 --- a/tools/kvm/term.c +++ b/tools/kvm/term.c @@ -127,13 +127,26 @@ void term_set_tty(int term) term_fds[term][TERM_FD_IN] = term_fds[term][TERM_FD_OUT] = master; } -void term_init(void) +int tty_parser(const struct option *opt, const char *arg, int unset) +{ + int tty = atoi(arg); + + term_set_tty(tty); + + return 0; +} + +int term_init(struct kvm *kvm) { struct termios term; - int i; + int i, r; + + r = tcgetattr(STDIN_FILENO, &orig_term); + if (r < 0) { + pr_warning("unable to save initial standard input settings"); + return r; + } - if (tcgetattr(STDIN_FILENO, &orig_term) < 0) - die("unable to save initial standard input settings"); term = orig_term; term.c_lflag &= ~(ICANON | ECHO | ISIG); @@ -147,4 +160,11 @@ void term_init(void) signal(SIGTERM, term_sig_cleanup); atexit(term_cleanup); + + return 0; +} + +int term_exit(struct kvm *kvm) +{ + return 0; }