bin/amdumpext
changeset 6 452350b85682
parent 5 5488aa9488af
child 7 29ca93ca12e0
equal deleted inserted replaced
5:5488aa9488af 6:452350b85682
    15 # filesystems.
    15 # filesystems.
    16 
    16 
    17 use 5.010;
    17 use 5.010;
    18 use strict;
    18 use strict;
    19 use warnings;
    19 use warnings;
       
    20 use Carp;
    20 use Pod::Usage;
    21 use Pod::Usage;
    21 use Getopt::Long;
    22 use Getopt::Long;
    22 use File::Basename;
    23 use File::Basename;
    23 use POSIX;
    24 use POSIX;
    24 
    25 
   240                     };
   241                     };
   241                     exec 'restore', -tvf => '-';
   242                     exec 'restore', -tvf => '-';
   242                     die "Can't exec `restore -tvf -`: $!";
   243                     die "Can't exec `restore -tvf -`: $!";
   243                 };
   244                 };
   244 
   245 
       
   246 		# the restore may close it's input, we'll get
       
   247 		# a SIG{PIPE} because of this
       
   248 		local $SIG{PIPE} = sub { 
       
   249 		    close $restore;
       
   250 		    $restore = undef;
       
   251 		    $SIG{PIPE} = 'default';
       
   252 		};
       
   253 
   245                 local $/ = \(my $x = 64 * 1024);
   254                 local $/ = \(my $x = 64 * 1024);
   246                 while (<STDIN>) {
   255                 while (<STDIN>) {
   247                     print $_;
   256                     print $_;
   248                     print $restore $_;
   257                     print $restore $_ if $restore;
   249                 }
   258                 }
   250 		close($restore);
   259 		close($restore) if $restore;
   251                 exit 0;
   260                 exit 0;
   252             };
   261             };
   253 	    
   262 	    
   254             open(STDERR, '|-') or do {
   263             open(STDERR, '|-') or do {
   255 		$0 = "$ME [stderr < dump]";
   264 		$0 = "$ME [stderr < dump]";
   287         open(STDERR, '|-') or do {
   296         open(STDERR, '|-') or do {
   288             postprocess_dump_messages($msg);
   297             postprocess_dump_messages($msg);
   289             exit 0;
   298             exit 0;
   290         };
   299         };
   291         exec @dump;
   300         exec @dump;
   292         die "Can't exec `@dump`: $!\n";
   301         die "Can't exec `@dump': $!\n";
   293     }
   302     }
   294     waitpid($pid, 0);
   303     waitpid($pid, 0);
   295     exit $?;
   304     exit $?;
   296 
   305 
   297 }
   306 }
   328     #
   337     #
   329     # the more generic solution would be to force
   338     # the more generic solution would be to force
   330     # restore to use a \0 separated output format
   339     # restore to use a \0 separated output format
   331 
   340 
   332     select +shift;
   341     select +shift;
   333     local $/ = "\n";	# make sure to have it line separated!
   342     die 'IFS is not as expected!' if $/ ne "\n";
       
   343 
   334 
   344 
   335     my $buffer = undef;
   345     my $buffer = undef;
   336     my $type   = undef;
   346     my $type   = undef;
   337 
   347 
   338     while (1) {
   348     while (1) {
   341 
   351 
   342         # skip the header lines
   352         # skip the header lines
   343         if (1 .. defined && /\Adir\s+\d+\s+(.*)\Z/) {
   353         if (1 .. defined && /\Adir\s+\d+\s+(.*)\Z/) {
   344             $buffer = '';
   354             $buffer = '';
   345             $type   = 'dir';
   355             $type   = 'dir';
   346 	    die "Unexpected end of input\n" if not defined;
   356 	    die "Unexpected end of input while reading from restore -tvf\n" if not defined;
   347             next;
   357             next;
   348         }
   358         }
   349 
   359 
   350         # if we match really good the buffer may be output
   360         # if we match really good the buffer may be output
   351         if (not defined
   361         if (not defined