mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Michael Ellerman <michael@ellerman.id.au>
To: <penberg@kernel.org>
Cc: <kvm@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH 3/6] kvm tools: Rework stdio/stdout handling to support redirection
Date: Wed,  6 Feb 2013 19:19:13 +1100	[thread overview]
Message-ID: <1360138756-1991-3-git-send-email-michael@ellerman.id.au> (raw)
In-Reply-To: <1360138756-1991-1-git-send-email-michael@ellerman.id.au>

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>
---
 tools/kvm/term.c |   15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/tools/kvm/term.c b/tools/kvm/term.c
index 4413450..fa85e4a 100644
--- a/tools/kvm/term.c
+++ b/tools/kvm/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);
 
-- 
1.7.10.4


  parent reply	other threads:[~2013-02-06  8:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-06  8:19 [PATCH 1/6] kvm tools: Return error status in lkvm list Michael Ellerman
2013-02-06  8:19 ` [PATCH 2/6] kvm tools: More error handling in the ipc code Michael Ellerman
2013-02-06  8:19 ` Michael Ellerman [this message]
2013-02-06  8:19 ` [PATCH 4/6] kvm tools: powerpc: Fix buglet in xics_init() handling of nrcpus Michael Ellerman
2013-02-06  8:19 ` [PATCH 5/6] kvm tools: powerpc: Add cpu info entry for POWER8 Michael Ellerman
2013-02-06  8:19 ` [PATCH 6/6] kvm tools: powerpc: Only emit TB freq if it's non-zero Michael Ellerman
2013-02-06 11:16 ` [PATCH 1/6] kvm tools: Return error status in lkvm list Pekka Enberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1360138756-1991-3-git-send-email-michael@ellerman.id.au \
    --to=michael@ellerman.id.au \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=penberg@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®