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> --- 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 <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; } -- 1.7.12 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html