X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=server-src%2Famreport.pl;h=b2913eb046580ba86b8d95f9cb0f6f9e687cf9eb;hb=HEAD;hp=cb3127579d49bc96a40cc7888c2fca022ba5ebe0;hpb=011a59f5a54864108a16af570a6b287410597cc2;p=debian%2Famanda diff --git a/server-src/amreport.pl b/server-src/amreport.pl index cb31275..b2913eb 100755 --- a/server-src/amreport.pl +++ b/server-src/amreport.pl @@ -1,9 +1,10 @@ #! @PERL@ -# Copyright (c) 2010 Zmanda, Inc. All Rights Reserved. +# Copyright (c) 2010-2012 Zmanda, Inc. All Rights Reserved. # -# This program is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License version 2 as published -# by the Free Software Foundation. +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY @@ -347,8 +348,29 @@ sub open_printer_output debug("invoking printer: " . join(" ", @cmd)); # redirect stdout/stderr to stderr, which is usually the amdump log - my $pid = open3( my $fh, ">&2", ">&2", @cmd) - or error("cannot start $cmd[0]: $!", 1); + my ($pid, $fh); + if (!-f $Amanda::Constants::LPR || !-x $Amanda::Constants::LPR) { + my $errstr = "error: the mailer '$Amanda::Constants::LPR' is not an executable program."; + print STDERR "$errstr\n"; + if ($mode == MODE_SCRIPT) { + debug($errstr); + } else { + error($errstr, 1); + } + } else { + eval { $pid = open3($fh, ">&2", ">&2", @cmd); } or do { + ($pid, $fh) = (0, undef); + chomp $@; + my $errstr = "error: $@: $!"; + + print STDERR "$errstr\n"; + if ($mode == MODE_SCRIPT) { + debug($errstr); + } else { + error($errstr, 1); + } + }; + } return ($pid, $fh); } @@ -398,18 +420,29 @@ sub open_mail_output my ($pid, $fh); - eval { $pid = open3($fh, ">&2", ">&2", @cmd); 1; } or do { - - ($pid, $fh) = (0, undef); - my $errstr = - "error: could not run command: " . join(" ", @cmd) . ": $@"; - + if (!-f $cfg_mailer || !-x $cfg_mailer) { + my $errstr = "error: the mailer '$cfg_mailer' is not an executable program."; + print STDERR "$errstr\n"; if ($mode == MODE_SCRIPT) { debug($errstr); } else { error($errstr, 1); } - }; + + } else { + eval { $pid = open3($fh, ">&2", ">&2", @cmd) } or do { + ($pid, $fh) = (0, undef); + chomp $@; + my $errstr = "error: $@: $!"; + + print STDERR "$errstr\n"; + if ($mode == MODE_SCRIPT) { + debug($errstr); + } else { + error($errstr, 1); + } + }; + } return ($pid, $fh); } @@ -431,21 +464,23 @@ sub run_output { # TODO: add some generic error handling here. must be compatible # with legacy behavior. - # TODO: modularize these better - if ($reportspec->[0] eq 'xml') { - print $fh $report->xml_output("" . getconf($CNF_ORG), $config_name); - } elsif ($reportspec->[0] eq 'human') { - my $hr = - Amanda::Report::human->new( $report, $fh, $config_name, $opt_logfname ); - $hr->print_human_amreport(); - } elsif ($reportspec->[0] eq 'postscript') { - use Amanda::Report::postscript; - my $rep = - Amanda::Report::postscript->new( $report, $config_name, $opt_logfname ); - $rep->write_report($fh); - } + if (defined $fh) { + # TODO: modularize these better + if ($reportspec->[0] eq 'xml') { + print $fh $report->xml_output("" . getconf($CNF_ORG), $config_name); + } elsif ($reportspec->[0] eq 'human') { + my $hr = Amanda::Report::human->new($report, $fh, $config_name, + $opt_logfname ); + $hr->print_human_amreport(); + } elsif ($reportspec->[0] eq 'postscript') { + use Amanda::Report::postscript; + my $rep = Amanda::Report::postscript->new($report, $config_name, + $opt_logfname ); + $rep->write_report($fh); + } - close $fh; + close $fh; + } # clean up any subprocess if (defined $pid) { @@ -464,6 +499,7 @@ Amanda::Util::setup_application("amreport", "server", $CONTEXT_CMDLINE); my $config_overrides = new_config_overrides( scalar(@ARGV) + 1 ); +debug("Arguments: " . join(' ', @ARGV)); Getopt::Long::Configure(qw/bundling/); GetOptions(