[tip:tools/kvm] kvm tools: improve term init/exit functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Commit-ID:  863538b00ecf7f2034a460f1888a7786ea6276af
Gitweb:     http://git.kernel.org/tip/863538b00ecf7f2034a460f1888a7786ea6276af
Author:     Sasha Levin <levinsasha928@xxxxxxxxx>
AuthorDate: Wed, 5 Sep 2012 10:31:48 +0200
Committer:  Pekka Enberg <penberg@xxxxxxxxxx>
CommitDate: Wed, 5 Sep 2012 16:22:37 +0300

kvm tools: improve term init/exit functions

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 <levinsasha928@xxxxxxxxx>
Signed-off-by: Pekka Enberg <penberg@xxxxxxxxxx>
---
 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 944ef3d..d007927 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 <sys/uio.h>
 #include <stdbool.h>
 
@@ -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;
 }
--
To unsubscribe from this list: send the line "unsubscribe linux-tip-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Stable Commits]     [Linux Stable Kernel]     [Linux Kernel]     [Linux USB Devel]     [Linux Video &Media]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux