Skip to content

Commit 8557b8e

Browse files
committed
Merge tag 'ktest-v4.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-ktest
Pull ktest fixes from Steven Rostedt: "Greg Kroah-Hartman reported to me that the ktest of v4.11-rc1 locked up in an infinite loop while doing the make mrproper. Looking into the cause I noticed that a recent update to the function run_command (used for running all shell commands, including "make mrproper") changed the internal loop to use the function wait_for_input. The wait_for_input function uses select to look at two file descriptors. One is the file descriptor of the command it is running, the other is STDIN. The STDIN check was not checking the return status of the sysread call, and was also just writing a lot of data into syswrite without regard to the size of the data read. Changing the code to check the return status of sysread, and also to still process the passed in descriptor data without looping back to the select fixed Greg's problem. While looking at this code I also realized that the loop did not honor the timeout if STDIN always had input (or for some reason return error). this could prevent wait_for_input to timeout on the file descriptor it is suppose to be waiting for. That is fixed too" * tag 'ktest-v4.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-ktest: ktest: Make sure wait_for_input does honor the timeout ktest: Fix while loop in wait_for_input
2 parents 04bb94b + f7c6401 commit 8557b8e

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

tools/testing/ktest/ktest.pl

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,6 +1880,7 @@ sub get_grub_index {
18801880
sub wait_for_input
18811881
{
18821882
my ($fp, $time) = @_;
1883+
my $start_time;
18831884
my $rin;
18841885
my $rout;
18851886
my $nr;
@@ -1895,17 +1896,22 @@ sub wait_for_input
18951896
vec($rin, fileno($fp), 1) = 1;
18961897
vec($rin, fileno(\*STDIN), 1) = 1;
18971898

1899+
$start_time = time;
1900+
18981901
while (1) {
18991902
$nr = select($rout=$rin, undef, undef, $time);
19001903

1901-
if ($nr <= 0) {
1902-
return undef;
1903-
}
1904+
last if ($nr <= 0);
19041905

19051906
# copy data from stdin to the console
19061907
if (vec($rout, fileno(\*STDIN), 1) == 1) {
1907-
sysread(\*STDIN, $buf, 1000);
1908-
syswrite($fp, $buf, 1000);
1908+
$nr = sysread(\*STDIN, $buf, 1000);
1909+
syswrite($fp, $buf, $nr) if ($nr > 0);
1910+
}
1911+
1912+
# The timeout is based on time waiting for the fp data
1913+
if (vec($rout, fileno($fp), 1) != 1) {
1914+
last if (defined($time) && (time - $start_time > $time));
19091915
next;
19101916
}
19111917

@@ -1917,12 +1923,11 @@ sub wait_for_input
19171923
last if ($ch eq "\n");
19181924
}
19191925

1920-
if (!length($line)) {
1921-
return undef;
1922-
}
1926+
last if (!length($line));
19231927

19241928
return $line;
19251929
}
1930+
return undef;
19261931
}
19271932

19281933
sub reboot_to {

0 commit comments

Comments
 (0)