ReadKeyMini: Restore STDIN flags in cooked()

This will probably resolve bug #946707: pt-sift loses STDIN after pt-diskstats
This commit is contained in:
Brian Fraser fraserb@gmail.com
2012-06-05 12:16:49 -03:00
parent 4906b52d3b
commit 6b93d51e43
3 changed files with 23 additions and 2 deletions

View File

@@ -1322,6 +1322,7 @@ use English qw(-no_match_vars);
use constant MKDEBUG => $ENV{MKDEBUG} || 0;
use POSIX qw( :termios_h );
use Fcntl qw( F_SETFL F_GETFL );
use base qw( Exporter );
@@ -1344,8 +1345,12 @@ my %modes = (
# This primarily comes from the Perl Cookbook, recipe 15.8
{
my $fd_stdin = fileno(STDIN);
my $flags;
unless ( $PerconaTest::DONT_RESTORE_STDIN ) {
$flags = fcntl(STDIN, F_GETFL, 0)
or die "can't fcntl F_GETFL: $!";
}
my $term = POSIX::Termios->new();
$term->getattr($fd_stdin);
my $oterm = $term->getlflag();
@@ -1376,6 +1381,10 @@ my %modes = (
$term->setlflag($oterm);
$term->setcc( VTIME, 0 );
$term->setattr( $fd_stdin, TCSANOW );
unless ( $PerconaTest::DONT_RESTORE_STDIN ) {
fcntl(STDIN, F_SETFL, $flags)
or die "can't fcntl F_SETFL: $!";
}
}
END { cooked() }
@@ -3407,7 +3416,7 @@ use English qw(-no_match_vars);
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
sub main {
@ARGV = @_; # set global ARGV for this package
local @ARGV = @_; # set global ARGV for this package
# ########################################################################
# Get configuration information.

View File

@@ -40,6 +40,7 @@ use English qw(-no_match_vars);
use constant MKDEBUG => $ENV{MKDEBUG} || 0;
use POSIX qw( :termios_h );
use Fcntl qw( F_SETFL F_GETFL );
use base qw( Exporter );
@@ -68,6 +69,11 @@ my %modes = (
{
my $fd_stdin = fileno(STDIN);
my $flags;
unless ( $PerconaTest::DONT_RESTORE_STDIN ) {
$flags = fcntl(STDIN, F_GETFL, 0)
or die "can't fcntl F_GETFL: $!";
}
my $term = POSIX::Termios->new();
$term->getattr($fd_stdin);
my $oterm = $term->getlflag();
@@ -98,6 +104,10 @@ my %modes = (
$term->setlflag($oterm);
$term->setcc( VTIME, 0 );
$term->setattr( $fd_stdin, TCSANOW );
unless ( $PerconaTest::DONT_RESTORE_STDIN ) {
fcntl(STDIN, F_SETFL, $flags)
or die "can't fcntl F_SETFL: $!";
}
}
END { cooked() }

View File

@@ -92,6 +92,8 @@ sub test_diskstats_file {
no_diff(
sub {
tie local *STDIN, TestInteractive => @commands;
local $PerconaTest::DONT_RESTORE_STDIN =
$PerconaTest::DONT_RESTORE_STDIN = 1;
pt_diskstats::main(
@options,
'--group-by', $groupby,