Skip to content

Commit 99c014a

Browse files
committed
ktest: Fix while loop in wait_for_input
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 <[email protected]> Tested-by: Greg Kroah-Hartman <[email protected]> Fixes: 6e98d1b ("ktest: Add timeout to ssh command") Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 5739438 commit 99c014a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

tools/testing/ktest/ktest.pl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,11 +1904,12 @@ sub wait_for_input
19041904

19051905
# copy data from stdin to the console
19061906
if (vec($rout, fileno(\*STDIN), 1) == 1) {
1907-
sysread(\*STDIN, $buf, 1000);
1908-
syswrite($fp, $buf, 1000);
1909-
next;
1907+
$nr = sysread(\*STDIN, $buf, 1000);
1908+
syswrite($fp, $buf, $nr) if ($nr > 0);
19101909
}
19111910

1911+
next if (vec($rout, fileno($fp), 1) != 1);
1912+
19121913
$line = "";
19131914

19141915
# try to read one char at a time

0 commit comments

Comments
 (0)