Imported Debian patch 2.5.1-1
[debian/amanda] / server-src / amstatus.pl.in
index 9a702534fdb00ade0a35afd3633be934d7c60ad3..e4ad2aa1de07a0d4275923c94fa51f5fe4a1996c 100644 (file)
@@ -53,10 +53,22 @@ else {
        }
 }
 
+#untaint user input $ARGV[0]
+
+if ($conf =~ /^([\w.-]+)$/) {          # $1 is untainted
+   $conf = $1;
+} else {
+    die "filename '$conf' has invalid characters.\n";
+}
+
+
 if ( ! -d "$confdir/$conf" ) {
     die "amstatus$suf: could not find directory $confdir/$conf";
 }
 
+$oldPATH = $ENV{'PATH'};
+$ENV{'PATH'} = "/bin:/usr/bin:/usr/sbin:/sbin";       # force known path
+
 $pwd = `pwd`;
 chomp $pwd;
 chdir "$confdir/$conf";
@@ -93,6 +105,7 @@ if($nb_options == 0 ) {
 }
 
 $unit=`$sbindir/amgetconf$suf displayunit`;
+$ENV{'PATH'} = $oldPATH;
 chomp($unit);
 $unitdivisor=1;
 if($unit eq 'K') {
@@ -166,7 +179,14 @@ while(<AMDUMP>) {
                        push @datestamp, $gdatestamp;
                }
        }
-       elsif(/setup_estimate: (\S+):(\S+): command .*, options: *(\S+) *last_level -?\d+ next_level0 -?\d+ level_days \d+ *getting estimates (-?\d) \(-2\) (-?\d) \(-2\) (-?\d) \(-2\)/) {
+       elsif(/planner: timestamp (\S+)/) {
+               $gdatestamp = $1;
+               if(!defined $datestamp{$gdatestamp}) {
+                       $datestamp{$gdatestamp} = 1;
+                       push @datestamp, $gdatestamp;
+               }
+       }
+       elsif(/setup_estimate: ([_\-\d\.A-Za-z]*):(\S+): command .*, options: *(\S+) *last_level -?\d+ next_level0 -?\d+ level_days \d+ *getting estimates (-?\d) \(-2\) (-?\d) \(-2\) (-?\d) \(-2\)/) {
                $host=$1;
                $partition=$2;
                $hostpart=&make_hostpart($host,$partition,$gdatestamp);
@@ -346,7 +366,6 @@ while(<AMDUMP>) {
                $dump_started{$hostpart}=1;
                $dump_time{$hostpart}=$1;
                $dump_finished{$hostpart}=0;
-               $holding_file{$hostpart}=$5;
                if(     $level{$hostpart} != $8 &&
                   $degr_level{$hostpart} == $8) {
                        $level{$hostpart}=$degr_level{$hostpart};
@@ -357,6 +376,7 @@ while(<AMDUMP>) {
                }
                $running_dumper{$2} = $hostpart;
                $error{$hostpart}="";
+               $size{$hostpart} = 0;
                $dumpers_active++;
                if(! defined($dumpers_active[$dumpers_active])) {
                        $dumpers_active[$dumpers_active]=0;
@@ -365,6 +385,32 @@ while(<AMDUMP>) {
                        $dumpers_held[$dumpers_active]={};
                }
        }
+       elsif(/driver: send-cmd time (\S+) to (chunker\d*): (PORT-WRITE) (\d+-\d+) (\S+) (\S+) (\S+) (\d+)/) {
+               $current_time=$1;
+               $host=$6;
+               $partition=$7;
+               $hostpart=&make_hostpart($host,$partition,$gdatestamp);
+               $serial=$4;
+               $serial{$serial}=$hostpart;
+               #$chunk_started{$hostpart}=1;
+               #$chunk_time{$hostpart}=$1;
+               #$chunk_finished{$hostpart}=0;
+               $holding_file{$hostpart}=$5;
+       }
+       elsif(/driver: send-cmd time (\S+) to (chunker\d*): (PORT-WRITE) (\d+-\d+) (\S+) (\S+) (\S+) (\S+) (\d+)/) {
+               $current_time=$1;
+               $host=$6;
+               $features=$7;
+               $features=$features;
+               $partition=$8;
+               $hostpart=&make_hostpart($host,$partition,$gdatestamp);
+               $serial=$4;
+               $serial{$serial}=$hostpart;
+               #$chunk_started{$hostpart}=1;
+               #$chunk_time{$hostpart}=$1;
+               #$chunk_finished{$hostpart}=0;
+               $holding_file{$hostpart}=$5;
+       }
        elsif(/driver: send-cmd time (\S+) to (dumper\d*): (FILE-DUMP|PORT-DUMP) (\d+-\d+) (\S+) (\S+) (\S+) (\S+) (\d+)/) {
                $current_time=$1;
                $host=$6;
@@ -388,6 +434,7 @@ while(<AMDUMP>) {
                }
                $running_dumper{$2} = $hostpart;
                $error{$hostpart}="";
+               $size{$hostpart} = 0;
                $dumpers_active++;
                if(! defined($dumpers_active[$dumpers_active])) {
                        $dumpers_active[$dumpers_active]=0;
@@ -421,6 +468,7 @@ while(<AMDUMP>) {
                }
                $running_dumper{$2} = $hostpart;
                $error{$hostpart}="";
+               $size{$hostpart} = 0;
                $dumpers_active++;
                if(! defined($dumpers_active[$dumpers_active])) {
                        $dumpers_active[$dumpers_active]=0;
@@ -429,7 +477,7 @@ while(<AMDUMP>) {
                        $dumpers_held[$dumpers_active]={};
                }
        }
-       elsif(/driver: send-cmd time (\S+) to (dumper\d*): CONTINUE (\d+-\d+) (\S+) (\d+) (\d+)/) {
+       elsif(/driver: send-cmd time (\S+) to (chunker\d*): CONTINUE (\d+-\d+) (\S+) (\d+) (\d+)/) {
                $current_time=$1;
                $serial=$3;
                $hostpart=$serial{$serial};
@@ -463,11 +511,11 @@ while(<AMDUMP>) {
                $error{$hostpart}="driver: (aborted:$error)";
                $dumpers_active--;
        }
-       elsif(/driver: result time (\S+) from (dumper\d+): DONE (\d+-\d+) (\d+) (\d+) (\d+) \[.*\]/) {
+       elsif(/driver: result time (\S+) from (dumper\d+): (DONE|PARTIAL) (\d+-\d+) (\d+) (\d+) (\d+) "?\[.*\]"?/) {
                $current_time=$1;
-               $serial=$3;
-               $origsize=$4 / $unitdivisor;
-               $outputsize=$5 / $unitdivisor;
+               $serial=$4;
+               $origsize=$5 / $unitdivisor;
+               $outputsize=$6 / $unitdivisor;
                $hostpart=$serial{$serial};
                $size{$hostpart}=$outputsize;
                $dump_finished{$hostpart}=1;
@@ -476,6 +524,30 @@ while(<AMDUMP>) {
                $dump_time{$hostpart}=$1;
                $error{$hostpart}="";
                $dumpers_active--;
+               if ($3 eq "PARTIAL") {
+                       $partial{$hostpart} = 1;
+               }
+               else {
+                       $partial{$hostpart} = 0;
+               }
+       }
+       elsif(/driver: result time (\S+) from (chunker\d+): (DONE|PARTIAL) (\d+-\d+) (\d+) "?\[.*\]"?/) {
+               $current_time=$1;
+               $serial=$4;
+               $outputsize=$5 / $unitdivisor;
+               $hostpart=$serial{$serial};
+               $size{$hostpart}=$outputsize;
+               $dump_finished{$hostpart}=1;
+               $busy_time{$2}+=($1-$dump_time{$hostpart});
+               $running_dumper{$2} = "0";
+               $dump_time{$hostpart}=$1;
+               $error{$hostpart}="";
+               if ($3 eq "PARTIAL") {
+                       $partial{$hostpart} = 1;
+               }
+               else {
+                       $partial{$hostpart} = 0;
+               }
        }
        elsif(/driver: result time (\S+) from (dumper\d+): ABORT-FINISHED (\d+-\d+)/) {
                $current_time=$1;
@@ -489,7 +561,7 @@ while(<AMDUMP>) {
                $error{$hostpart}="driver: (aborted)";
                $dumpers_active--;
        }
-       elsif(/driver: result time (\S+) from (dumper\d+): RQ-MORE-DISK (\d+-\d+)/) {
+       elsif(/driver: result time (\S+) from (chunker\d+): RQ-MORE-DISK (\d+-\d+)/) {
                $current_time=$1;
                $serial=$3;
                $hostpart=$serial{$serial};
@@ -524,7 +596,6 @@ while(<AMDUMP>) {
                if(!defined $level{$hostpart}) {
                        $level{$hostpart} = $level;
                }
-               $serial{$serial}=$hostpart;
                $taper_started{$hostpart}=1;
                $taper_finished{$hostpart}=0;
                $taper_time{$hostpart}=$1;
@@ -548,7 +619,6 @@ while(<AMDUMP>) {
                if(!defined $level{$hostpart}) {
                        $level{$hostpart} = $level;
                }
-               $serial{$serial}=$hostpart;
                $taper_started{$hostpart}=1;
                $taper_finished{$hostpart}=0;
                $taper_time{$hostpart}=$1;
@@ -576,11 +646,11 @@ while(<AMDUMP>) {
                $taper_finished{$hostpart}=0;
                $taper_time{$hostpart}=$1;
        }
-       elsif(/driver: result time (\S+) from taper: DONE (\d+-\d+) (\S+) (\d+) \[sec (\S+) kb (\d+) kps/) {
+       elsif(/driver: result time (\S+) from taper: (DONE|PARTIAL) (\d+-\d+) (\S+) (\d+) "?\[sec (\S+) kb (\d+) kps/) {
                $current_time=$1;
-               $serial=$2;
-               $label=$3;
-               $size=$6 / $unitdivisor;
+               $serial=$3;
+               $label=$4;
+               $size=$7 / $unitdivisor;
                $hostpart=$serial{$serial};
                $taper_finished{$hostpart}=1;
                $busy_time{"taper"}+=($1-$taper_time{$hostpart});
@@ -596,6 +666,12 @@ while(<AMDUMP>) {
                else {
                        $ntesize{$nb_tape} += $size{$hostpart};
                }
+               if ($3 eq "PARTIAL") {
+                       $partial{$hostpart} = 1;
+               }
+               else {
+                       $partial{$hostpart} = 0;
+               }
        }
        elsif(/driver: result time (\S+) from taper: (TRY-AGAIN|TAPE-ERROR) (\d+-\d+) (.+)/) {
                $current_time=$1;
@@ -735,7 +811,8 @@ foreach $host (sort @hosts) {
                        $hostpart=&make_hostpart($host,$partition,$datestamp);
                        next if(!defined $estimate{$hostpart} && !defined $flush{$hostpart});
                        $nb_partition++;
-                       if( !defined $size{$hostpart} && defined $holding_file{$hostpart}) {
+                       if( (!defined $size{$hostpart} || $size{$hostpart} == 0) &&
+                                defined $holding_file{$hostpart}) {
                                $size{$hostpart} = &dump_size($holding_file{$hostpart}) / (1024 * $unitdivisor);
                        }
                        $in_flush=0;
@@ -904,6 +981,8 @@ foreach $host (sort @hosts) {
                                                        if( defined $starttime ) {
                                                                print " (", &showtime($taper_time{$hostpart}), ")";
                                                        }
+                                                       print ", PARTIAL" if defined $partial{$hostpart} &&
+                                                                                                          $partial{$hostpart} == 1;
                                                        print "\n";
                                                }
                                                $tpartition++;
@@ -989,7 +1068,10 @@ foreach $host (sort @hosts) {
                                                        if( defined $starttime ) {
                                                                print " (", &showtime($dump_time{$hostpart}), ")";
                                                        }
-                                                       print ", wait for writing to tape\n";
+                                                       print ", wait for writing to tape";
+                                                  print ", PARTIAL" if defined $partial{$hostpart} &&
+                                                                                                               $partial{$hostpart} == 1;;
+                                                       print "\n";
                                                }
                                                $dpartition++;
                                                $dsize += $size{$hostpart};
@@ -1009,7 +1091,10 @@ foreach $host (sort @hosts) {
                                                printf "%8s ", $datestamp if defined $opt_date;
                                                printf "%-${maxnamelength}s%2d", "$host:$partition", $level{$hostpart};
                                                printf "%9d$unit", $size{$hostpart};
-                                               print " waiting to flush\n";
+                                               print " waiting to flush";
+                                               print ", PARTIAL" if defined $partial{$hostpart} &&
+                                                                                                  $partial{$hostpart} == 1;
+                                               print "\n";
                                        }
                                        $wfpartition++;
                                        $wfsize += $size{$hostpart};