aboutsummaryrefslogtreecommitdiffstats
path: root/term.c
diff options
context:
space:
mode:
authorMichael Ellerman <michael@ellerman.id.au>2013-02-06 19:19:13 +1100
committerWill Deacon <will.deacon@arm.com>2015-06-01 16:39:54 +0100
commit36ad4dcfdd5342de1985f5f9846325f8880d7c4c (patch)
tree4aed92dfab51d57a80608206ba48c0d83d713dae /term.c
parent211370d69e62335e3345aae5c52e935b11307acf (diff)
downloadkvmtool-36ad4dcfdd5342de1985f5f9846325f8880d7c4c.tar.gz
kvm tools: Rework stdio/stdout handling to support redirection
Currently if you redirect the output from "lkvm run" to a file then term_init() will fail, because it can't call the terminal ioctls. So check if stdin and stdout are ttys, if either is not then skip the rest of the terminal setup. Redirecting one but not the other is a little odd, but does work. Note that we skip registering the cleanup routines, so we don't need to modify them. Signed-off-by: Michael Ellerman <michael@ellerman.id.au> Signed-off-by: Pekka Enberg <penberg@kernel.org>
Diffstat (limited to 'term.c')
-rw-r--r--term.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/term.c b/term.c
index 4413450f..fa85e4a5 100644
--- a/term.c
+++ b/term.c
@@ -140,6 +140,15 @@ int term_init(struct kvm *kvm)
struct termios term;
int i, r;
+ for (i = 0; i < 4; i++)
+ if (term_fds[i][TERM_FD_IN] == 0) {
+ term_fds[i][TERM_FD_IN] = STDIN_FILENO;
+ term_fds[i][TERM_FD_OUT] = STDOUT_FILENO;
+ }
+
+ if (!isatty(STDIN_FILENO) || !isatty(STDOUT_FILENO))
+ return 0;
+
r = tcgetattr(STDIN_FILENO, &orig_term);
if (r < 0) {
pr_warning("unable to save initial standard input settings");
@@ -151,12 +160,6 @@ int term_init(struct kvm *kvm)
term.c_lflag &= ~(ICANON | ECHO | ISIG);
tcsetattr(STDIN_FILENO, TCSANOW, &term);
- for (i = 0; i < 4; i++)
- if (term_fds[i][TERM_FD_IN] == 0) {
- term_fds[i][TERM_FD_IN] = STDIN_FILENO;
- term_fds[i][TERM_FD_OUT] = STDOUT_FILENO;
- }
-
signal(SIGTERM, term_sig_cleanup);
atexit(term_cleanup);