diff --git a/bin/pt-diskstats b/bin/pt-diskstats index f02dedfa..91bbb66b 100755 --- a/bin/pt-diskstats +++ b/bin/pt-diskstats @@ -1429,14 +1429,12 @@ my %modes = ( 'ultra-raw' => 5, ); - { - my $fd_stdin = fileno(STDIN); my $flags; unless ( $PerconaTest::DONT_RESTORE_STDIN ) { $flags = fcntl(STDIN, F_GETFL, 0) - or warn "can't fcntl F_GETFL: $!"; + or warn "Error getting STDIN flags with fcntl: $OS_ERROR"; } my $term = POSIX::Termios->new(); $term->getattr($fd_stdin); @@ -1468,14 +1466,13 @@ 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 warn "can't fcntl F_SETFL: $!"; + if ( !$PerconaTest::DONT_RESTORE_STDIN ) { + fcntl(STDIN, F_SETFL, int($flags)) + or warn "Error restoring STDIN flags with fcntl: $OS_ERROR"; } } END { cooked() } - } sub readkey { @@ -1484,14 +1481,12 @@ sub readkey { sysread(STDIN, $key, 1); my $timeout = 0.1; if ( $key eq "\033" ) { - { - my $x = ''; - STDIN->blocking(0); - sysread(STDIN, $x, 2); - STDIN->blocking(1); - $key .= $x; - redo if $key =~ /\[[0-2](?:[0-9];)?$/ - } + my $x = ''; + STDIN->blocking(0); + sysread(STDIN, $x, 2); + STDIN->blocking(1); + $key .= $x; + redo if $key =~ /\[[0-2](?:[0-9];)?$/ } cooked(); return $key; diff --git a/lib/ReadKeyMini.pm b/lib/ReadKeyMini.pm index ee915442..6bc620ed 100644 --- a/lib/ReadKeyMini.pm +++ b/lib/ReadKeyMini.pm @@ -1,4 +1,4 @@ -# This program is copyright 2010-2011 Percona Inc. +# This program is copyright 2010-2012 Percona Inc. # Feedback and improvements are welcome. # # THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED @@ -66,16 +66,12 @@ my %modes = ( ); # This primarily comes from the Perl Cookbook, recipe 15.8 - { -use Devel::Peek; -use Data::Dumper; - my $fd_stdin = fileno(STDIN); my $flags; unless ( $PerconaTest::DONT_RESTORE_STDIN ) { $flags = fcntl(STDIN, F_GETFL, 0) - or warn "can't fcntl F_GETFL: $!"; + or warn "Error getting STDIN flags with fcntl: $OS_ERROR"; } my $term = POSIX::Termios->new(); $term->getattr($fd_stdin); @@ -107,15 +103,13 @@ use Data::Dumper; $term->setlflag($oterm); $term->setcc( VTIME, 0 ); $term->setattr( $fd_stdin, TCSANOW ); - unless ( $PerconaTest::DONT_RESTORE_STDIN ) { - # if ( -t STDIN ) { warn "STD is tty\n"; } + if ( !$PerconaTest::DONT_RESTORE_STDIN ) { fcntl(STDIN, F_SETFL, int($flags)) - or warn "can't fcntl F_SETFL: $!"; + or warn "Error restoring STDIN flags with fcntl: $OS_ERROR"; } } END { cooked() } - } sub readkey { @@ -124,17 +118,16 @@ sub readkey { sysread(STDIN, $key, 1); my $timeout = 0.1; if ( $key eq "\033" ) { - # Ugly and broken hack, but good enough for the two minutes it took to write. - # Namely, Ctrl escapes, the F-NUM keys, and other stuff you can send from the keyboard - # take more than one "character" to represent, and would be wrong to break into pieces. - { - my $x = ''; - STDIN->blocking(0); - sysread(STDIN, $x, 2); - STDIN->blocking(1); - $key .= $x; - redo if $key =~ /\[[0-2](?:[0-9];)?$/ - } + # Ugly and broken hack, but good enough for the two minutes it took + # to write. Namely, Ctrl escapes, the F-NUM keys, and other stuff + # you can send from the keyboard take more than one "character" to + # represent, and would be wrong to break into pieces. + my $x = ''; + STDIN->blocking(0); + sysread(STDIN, $x, 2); + STDIN->blocking(1); + $key .= $x; + redo if $key =~ /\[[0-2](?:[0-9];)?$/ } cooked(); return $key; diff --git a/t/lib/Diskstats.t b/t/lib/Diskstats.t index 812e65a6..77761cbb 100644 --- a/t/lib/Diskstats.t +++ b/t/lib/Diskstats.t @@ -9,15 +9,13 @@ BEGIN { use strict; use warnings FATAL => 'all'; use English qw(-no_match_vars); -use Test::More; # tests => 108; - -use PerconaTest; - -use OptionParser; - +use Test::More; use File::Spec; use File::Temp (); +use PerconaTest; +use OptionParser; + BEGIN { use_ok "Diskstats"; use_ok "DiskstatsGroupByAll"; @@ -25,7 +23,7 @@ BEGIN { use_ok "DiskstatsGroupBySample"; } -my $o = new OptionParser(description => 'Diskstats'); +my $o = new OptionParser(description => 'Diskstats'); $o->get_specs("$trunk/bin/pt-diskstats"); $o->get_opts(); @@ -476,6 +474,7 @@ is_deeply( $obj->clear_state(); } + # ############################################################################ # The three subclasses # ############################################################################ @@ -491,7 +490,8 @@ for my $test ( { class => "DiskstatsGroupBySample", results_file_prefix => "sample", - }) { + }, +) { my $obj = $test->{class}->new(OptionParser => $o, show_inactive => 1); my $prefix = $test->{results_file_prefix}; @@ -502,9 +502,8 @@ for my $test ( $obj->set_show_line_between_samples(0); for my $filename ( map "diskstats-00$_.txt", 1..5 ) { - my $file = File::Spec->catfile( "t", "pt-diskstats", "samples", $filename ); - my $file_with_trunk = File::Spec->catfile( $trunk, $file ); - + my $file = File::Spec->catfile(qw(t pt-diskstats samples), $filename); + my $file_with_trunk = File::Spec->catfile($trunk, $file); my $expected = "t/pt-diskstats/expected/${prefix}_$filename"; ok( @@ -571,7 +570,6 @@ EOF qr/Time between samples should be > 0, is /, "$test->{class}, ->_calc_deltas fails if the time elapsed is negative" ); - } # ###########################################################################