mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-23 21:05:00 +00:00
Use int($flags) to prevent fcntl(F_SETFL) error. Clean up ReadKeyMini.pm and Diskstats.t.
This commit is contained in:
@@ -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,7 +1481,6 @@ sub readkey {
|
||||
sysread(STDIN, $key, 1);
|
||||
my $timeout = 0.1;
|
||||
if ( $key eq "\033" ) {
|
||||
{
|
||||
my $x = '';
|
||||
STDIN->blocking(0);
|
||||
sysread(STDIN, $x, 2);
|
||||
@@ -1492,7 +1488,6 @@ sub readkey {
|
||||
$key .= $x;
|
||||
redo if $key =~ /\[[0-2](?:[0-9];)?$/
|
||||
}
|
||||
}
|
||||
cooked();
|
||||
return $key;
|
||||
}
|
||||
|
@@ -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,10 +118,10 @@ 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.
|
||||
{
|
||||
# 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);
|
||||
@@ -135,7 +129,6 @@ sub readkey {
|
||||
$key .= $x;
|
||||
redo if $key =~ /\[[0-2](?:[0-9];)?$/
|
||||
}
|
||||
}
|
||||
cooked();
|
||||
return $key;
|
||||
}
|
||||
|
@@ -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";
|
||||
@@ -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"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
# ###########################################################################
|
||||
|
Reference in New Issue
Block a user