mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-10-19 17:04:00 +00:00
ReadKeyMini: Restore STDIN flags in cooked()
This will probably resolve bug #946707: pt-sift loses STDIN after pt-diskstats
This commit is contained in:
@@ -1322,6 +1322,7 @@ use English qw(-no_match_vars);
|
|||||||
use constant MKDEBUG => $ENV{MKDEBUG} || 0;
|
use constant MKDEBUG => $ENV{MKDEBUG} || 0;
|
||||||
|
|
||||||
use POSIX qw( :termios_h );
|
use POSIX qw( :termios_h );
|
||||||
|
use Fcntl qw( F_SETFL F_GETFL );
|
||||||
|
|
||||||
use base qw( Exporter );
|
use base qw( Exporter );
|
||||||
|
|
||||||
@@ -1344,8 +1345,12 @@ my %modes = (
|
|||||||
# This primarily comes from the Perl Cookbook, recipe 15.8
|
# This primarily comes from the Perl Cookbook, recipe 15.8
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
my $fd_stdin = fileno(STDIN);
|
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();
|
my $term = POSIX::Termios->new();
|
||||||
$term->getattr($fd_stdin);
|
$term->getattr($fd_stdin);
|
||||||
my $oterm = $term->getlflag();
|
my $oterm = $term->getlflag();
|
||||||
@@ -1376,6 +1381,10 @@ my %modes = (
|
|||||||
$term->setlflag($oterm);
|
$term->setlflag($oterm);
|
||||||
$term->setcc( VTIME, 0 );
|
$term->setcc( VTIME, 0 );
|
||||||
$term->setattr( $fd_stdin, TCSANOW );
|
$term->setattr( $fd_stdin, TCSANOW );
|
||||||
|
unless ( $PerconaTest::DONT_RESTORE_STDIN ) {
|
||||||
|
fcntl(STDIN, F_SETFL, $flags)
|
||||||
|
or die "can't fcntl F_SETFL: $!";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
END { cooked() }
|
END { cooked() }
|
||||||
@@ -3407,7 +3416,7 @@ use English qw(-no_match_vars);
|
|||||||
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
|
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
|
||||||
|
|
||||||
sub main {
|
sub main {
|
||||||
@ARGV = @_; # set global ARGV for this package
|
local @ARGV = @_; # set global ARGV for this package
|
||||||
|
|
||||||
# ########################################################################
|
# ########################################################################
|
||||||
# Get configuration information.
|
# Get configuration information.
|
||||||
|
@@ -40,6 +40,7 @@ use English qw(-no_match_vars);
|
|||||||
use constant MKDEBUG => $ENV{MKDEBUG} || 0;
|
use constant MKDEBUG => $ENV{MKDEBUG} || 0;
|
||||||
|
|
||||||
use POSIX qw( :termios_h );
|
use POSIX qw( :termios_h );
|
||||||
|
use Fcntl qw( F_SETFL F_GETFL );
|
||||||
|
|
||||||
use base qw( Exporter );
|
use base qw( Exporter );
|
||||||
|
|
||||||
@@ -68,6 +69,11 @@ my %modes = (
|
|||||||
{
|
{
|
||||||
|
|
||||||
my $fd_stdin = fileno(STDIN);
|
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();
|
my $term = POSIX::Termios->new();
|
||||||
$term->getattr($fd_stdin);
|
$term->getattr($fd_stdin);
|
||||||
my $oterm = $term->getlflag();
|
my $oterm = $term->getlflag();
|
||||||
@@ -98,6 +104,10 @@ my %modes = (
|
|||||||
$term->setlflag($oterm);
|
$term->setlflag($oterm);
|
||||||
$term->setcc( VTIME, 0 );
|
$term->setcc( VTIME, 0 );
|
||||||
$term->setattr( $fd_stdin, TCSANOW );
|
$term->setattr( $fd_stdin, TCSANOW );
|
||||||
|
unless ( $PerconaTest::DONT_RESTORE_STDIN ) {
|
||||||
|
fcntl(STDIN, F_SETFL, $flags)
|
||||||
|
or die "can't fcntl F_SETFL: $!";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
END { cooked() }
|
END { cooked() }
|
||||||
|
@@ -92,6 +92,8 @@ sub test_diskstats_file {
|
|||||||
no_diff(
|
no_diff(
|
||||||
sub {
|
sub {
|
||||||
tie local *STDIN, TestInteractive => @commands;
|
tie local *STDIN, TestInteractive => @commands;
|
||||||
|
local $PerconaTest::DONT_RESTORE_STDIN =
|
||||||
|
$PerconaTest::DONT_RESTORE_STDIN = 1;
|
||||||
pt_diskstats::main(
|
pt_diskstats::main(
|
||||||
@options,
|
@options,
|
||||||
'--group-by', $groupby,
|
'--group-by', $groupby,
|
||||||
|
Reference in New Issue
Block a user