1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
#! /usr/bin/perl
#
# This updated version of the rtas_dump script will
# do everything the original rtas_dump script does except
# it does it cleaner and without as many cmdline options.
#
# Copyright (C) 2004 International Business Machines
# Common Public License Version 1.0 (see COPYRIGHT)
#
# Author: Nathan Fontenot <nfont@linux.vnet.ibm.com>
#
use vars qw/ %opt /;
use Getopt::Long;
use File::Basename;
$re_decode = $ENV{RTAS_EVENT_DECODE} || "/usr/sbin/rtas_event_decode";
#
# usage statement
#
sub usage()
{
print "Usage: rtas_dump [OPTIONS]\n";
print "Dump the contents of an RTAS event, by default RTAS events\n";
print "are read from stdin unless the -f flag is used.\n\n";
print " -d debug flag, passed through to rtas_event_decode\n";
print " -f <FILE> dump the RTAS events from <FILE>\n";
print " -h print this message and exit\n";
print " -n <NUM> only dump RTAS event number <NUM>\n";
print " -v dump the entire RTAS event, not just the header\n";
print " -w <width> set the output character width\n";
exit 1;
}
#
# Read in the contents of an RTAS event and invoke rtas_event_decode on it.
#
sub handle_rtas_event()
{
my ($event_no) = @_;
$re_decode_args = "$re_decode_args -n $event_no";
# create the pipe to rtas_event_decode
open EVENT_DECODE, "| $re_decode $re_decode_args";
while(<$fh>) {
($crud, $data) = split (/RTAS/);
$rtas_str = $rtas_str . "RTAS" . $data;
if (/RTAS event end/) {
print EVENT_DECODE $rtas_str;
$rtas_str = "";
last;
}
}
close EVENT_DECODE;
}
#
# Main
#
my $PSERIES_PLATFORM = dirname(__FILE__) . "/pseries_platform";
my $perldumpenv='perl -MData::Dumper -e '."'".
'\$Data::Dumper::Terse=1;print Dumper(\%ENV);'."'";
eval '%ENV=('.$1.')' if `bash -c "
. $PSERIES_PLATFORM;
$perldumpenv"`
=~ /^\s*\{(.*)\}\s*$/mxs;
if ($ENV{'platform'} == $ENV{'PLATFORM_UNKNOWN'} || $ENV{'platform'} == $ENV{'PLATFORM_POWERKVM_HOST'}) {
print "rtas_dump: is not supported on the $ENV{'platform_name'} platform\n";
exit 1;
}
# process cmdline args
Getopt::Long::Configure("bundling");
GetOptions("help|h" => \$help_flag,
"dump_raw|d" => \$debug_flag,
"file|f=s" => \$filename,
"n=i" => \$event_no,
"w=i" => \$width,
"verbose|v+" => \$verbose) or usage();
usage() if $help_flag;
# make sure the rtas_event_decode application is available
-e $re_decode or die "File $re_decode does not exist and is needed by rtas_dump.\n";
-x $re_decode or die "File $re_decode is not executable.\n";
# get a reference to our input filehandle
if ($filename) {
if (-e $filename) {
open INPUT_FILE, $filename;
$fh = \*INPUT_FILE;
$close_input_file = 1;
} else {
print "File $filename does not exist\n" ;
return -1;
}
} else {
$fh = \*STDIN;
}
# create the arg list to rtas_event_decode
$re_decode_args = "$re_decode_args -d" if $debug_flag;
$re_decode_args = "$re_decode_args -v" if $verbose;
$re_decode_args = "$re_decode_args -w $width" if $width;
while (<$fh>) {
if (/RTAS event begin/) {
# found the beginning of an RTAS event, process it.
($crud, $data) = split (/RTAS:/);
($this_event_no, $d) = split (' ', $data);
if ($event_no) {
if ($event_no == $this_event_no) {
$rtas_str = $rtas_str . "RTAS:" . $data;
&handle_rtas_event($this_event_no);
}
} else {
$rtas_str = $rtas_str . "RTAS:" . $data;
&handle_rtas_event($this_event_no);
}
next;
}
}
if ($close_input_file) {
close INPUT_FILE;
}
|