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@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
This commit is contained in:
Sasha Levin
2012-09-05 10:31:48 +02:00
committed by Will Deacon
parent ba46fe53c6
commit dca745e48a
3 changed files with 38 additions and 15 deletions
+9 -10
View File
@@ -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);
+5 -1
View File
@@ -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 */
+24 -4
View File
@@ -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;
}