){ + chop; + my($long, $i, $driver) = /"(\S+)"\s+(\d+)\s+"(\S+)"/; + if( $long eq $dev ){ + $name = $driver . $i; + last; + } + } + close P; + + unless( $name ){ + print "error\n"; + exit -1; + } + + my $out = output_of_command( 'iostat', '-x', $name, 5, 2 ); + my @dat = split /\s+/, ((split /\n/, $out)[-1]); + + if( $stat eq 'total' ){ + my $res = $dat[3] + $dat[4]; # read + write + print "$res\n"; + }else{ + print "$dat[$n]\n"; + } + exit; + } + + if( $^O eq 'netbsd' ){ + my %STAT = (read => 4, write => 8); + my $n = $STAT{$stat}; + my $out = output_of_command( 'iostat', '-Dx', $disk, 5, 2 ); + my @dat = split /\s+/, ((split /\n/, $out)[-1]); + if( $stat eq 'total' ){ + print ($dat[4] + $dat[8]) * 1000, "\n"; + }else{ + print ($dat[$n] * 1000), "\n"; + } + exit; + } + + # ... +} + +sub zpool_status { + my $arg = shift; # pool name + + my $out = output_of_command( 'zpool', 'status', $arg ); + for my $l (split /\n/, $out){ + if( $l =~ /^\s+state:\s+(.*)/ ){ + my $v = $1; + print "$v\n"; + exit; + } + } + print "UNKNOWN\n"; +} + +sub kstat { + my $arg = shift; + + my $out = output_of_command( 'kstat', '-p', $arg ); + chomp($out); + my($key, $res) = split /\t/, $out, 2; + + print "$res\n"; +} + +################################################################ + sub output_of_command { my $cmd = shift; my @arg = @_; @@ -140,18 +271,18 @@ # get address of peer my $sk = getpeername(STDIN); die "getpeername failed: $!\n" unless $sk; - + my $af = unpack('xC', $sk); - my( $srcip, $scrport ); - + my( $srcip, $srcport ); + if( $HAVE_S6 && $af == AF_INET6 ){ ($srcport, $srcip) = unpack_sockaddr_in6($sk); }else{ ($srcport, $srcip) = sockaddr_in($sk); } - + $srcip = xxx_inet_ntoa($srcip); - + # check foreach my $a (@addr){ # canonicalize @@ -159,9 +290,9 @@ return 1 if $a eq $srcip; } - + die "access denied from $srcip\n"; - + } sub xxx_inet_ntoa { @@ -170,7 +301,7 @@ return inet_ntoa($n) if length($n) == 4; return undef unless $HAVE_S6; return inet_ntop(AF_INET6, $n) if length($n) == 16; - + "X.X.X.X"; }