Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1595311

[GIT PULL][PATCH 1/2] ktest: Fix while loop in wait_for_input

From Steven Rostedt <rostedt@goodmis.org>
Newsgroups linux.kernel
Subject [GIT PULL][PATCH 1/2] ktest: Fix while loop in wait_for_input
Date 2017-03-08 17:00 +0100
Message-ID <tiMam-bQ-23@gated-at.bofh.it> (permalink)
References <tiMam-bQ-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

The run_command function was changed to use the wait_for_input function to
allow having a timeout if the command to run takes too much time. There was
a bug in the wait_for_input where it could end up going into an infinite
loop. There's two issues here. One is that the return value of the sysread
wasn't used for the write (to write a proper size), and that it should
continue processing the passed in file descriptor too even if there was
input. There was no check for error, if for some reason STDIN returned an
error, the function would go into an infinite loop and never exit.

Reported-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Tested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Fixes: 6e98d1b4415f ("ktest: Add timeout to ssh command")
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 tools/testing/ktest/ktest.pl | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index 29470b554711..0c006a2f165d 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -1904,11 +1904,12 @@ sub wait_for_input
 
 	# copy data from stdin to the console
 	if (vec($rout, fileno(\*STDIN), 1) == 1) {
-	    sysread(\*STDIN, $buf, 1000);
-	    syswrite($fp, $buf, 1000);
-	    next;
+	    $nr = sysread(\*STDIN, $buf, 1000);
+	    syswrite($fp, $buf, $nr) if ($nr > 0);
 	}
 
+	next if (vec($rout, fileno($fp), 1) != 1);
+
 	$line = "";
 
 	# try to read one char at a time
-- 
2.10.2

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[GIT PULL][PATCH 0/2] ktest: Fixes for 4.11 Steven Rostedt <rostedt@goodmis.org> - 2017-03-08 17:00 +0100
  [GIT PULL][PATCH 1/2] ktest: Fix while loop in wait_for_input Steven Rostedt <rostedt@goodmis.org> - 2017-03-08 17:00 +0100
  [GIT PULL][PATCH 2/2] ktest: Make sure wait_for_input does honor the timeout Steven Rostedt <rostedt@goodmis.org> - 2017-03-08 17:00 +0100
  Re: [GIT PULL][PATCH 0/2] ktest: Fixes for 4.11 Steven Rostedt <rostedt@goodmis.org> - 2017-03-08 17:30 +0100

csiph-web