my $localversion;
my $iteration = 0;
my $successes = 0;
-my $stty;
+my $stty_orig;
my $bisect_good;
my $bisect_bad;
my $pid;
# save terminal settings
- $stty = `stty -g`;
+ $stty_orig = `stty -g`;
+
+ # place terminal in cbreak mode so that stdin can be read one character at
+ # a time without having to wait for a newline
+ system("stty -icanon -echo -icrnl");
create_pty($ptm, $pts);
close($fp);
# restore terminal settings
- system("stty $stty");
+ system("stty $stty_orig");
}
sub start_monitor {
{
my ($fp, $time) = @_;
my $rin;
- my $ready;
+ my $rout;
+ my $nr;
+ my $buf;
my $line;
my $ch;
$rin = '';
vec($rin, fileno($fp), 1) = 1;
- ($ready, $time) = select($rin, undef, undef, $time);
+ vec($rin, fileno(\*STDIN), 1) = 1;
- $line = "";
+ while (1) {
+ $nr = select($rout=$rin, undef, undef, $time);
- # try to read one char at a time
- while (sysread $fp, $ch, 1) {
- $line .= $ch;
- last if ($ch eq "\n");
- }
+ if ($nr <= 0) {
+ return undef;
+ }
- if (!length($line)) {
- return undef;
- }
+ # copy data from stdin to the console
+ if (vec($rout, fileno(\*STDIN), 1) == 1) {
+ sysread(\*STDIN, $buf, 1000);
+ syswrite($fp, $buf, 1000);
+ next;
+ }
- return $line;
+ $line = "";
+
+ # try to read one char at a time
+ while (sysread $fp, $ch, 1) {
+ $line .= $ch;
+ last if ($ch eq "\n");
+ }
+
+ if (!length($line)) {
+ return undef;
+ }
+
+ return $line;
+ }
}
sub reboot_to {