#
# Copyright (c) 2008-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
my $keep_label;
my $verbose = 1;
my $help;
-my $logdir;
-my $log_file;
-my $log_created = 0;
-
-sub die_handler {
- if ($log_created == 1) {
- unlink $log_file;
- $log_created = 0;
- }
-}
-$SIG{__DIE__} = \&die_handler;
-
-sub int_handler {
- if ($log_created == 1) {
- unlink $log_file;
- $log_created = 0;
- }
- die "Interrupted\n";
-}
-$SIG{INT} = \&int_handler;
sub usage() {
print <<EOF
}
Amanda::Util::finish_setup($RUNNING_AS_DUMPUSER);
-$logdir = config_dir_relative(getconf($CNF_LOGDIR));
-$log_file = "$logdir/log";
-
-if ($erase) {
- # Check for log file existance
- if (-e $log_file) {
- `amcleanup -p $config_name`;
- }
-
- if (-e $log_file) {
- local *LOG;
- open(LOG, $log_file);
- my $info_line = <LOG>;
- close LOG;
- $info_line =~ /^INFO (.*) .* pid .*$/;
- my $process_name = $1;
- print "$process_name is running, or you must run amcleanup\n";
- exit 1;
- }
-}
# amadmin may later try to load this and will die if it has errors
# load it now to catch the problem sooner (before we might erase data)
$tapelist->write();
}
- my $tmp_curinfo_file = "$AMANDA_TMPDIR/curinfo-amrmtape-" . time();
+ my $tmp_curinfo_file = "$AMANDA_TMPDIR/curinfo-amrmtape-" . time() . "-" . $$;
unless (open(AMADMIN, "$amadmin $config_name export |")) {
die "Failed to execute $amadmin: $! $?";
}
- open(CURINFO, ">$tmp_curinfo_file");
+ open(CURINFO, ">$tmp_curinfo_file") or
+ die "Failed to open $tmp_curinfo_file for writing: $! $?";
sub info_line($) {
print CURINFO "$_[0]";
my $erase_volume = make_cb('erase_volume' => sub {
if ($erase) {
- $log_created = 1;
- local *LOG;
- open(LOG, ">$log_file");
- print LOG "INFO amrmtape amrmtape pid $$\n";
- close LOG;
my $chg = Amanda::Changer->new($changer_name, tapelist => $tapelist);
$chg->load(
'label' => $label,
$erase_volume->();
Amanda::MainLoop::run();
-if ($log_created == 1) {
- unlink $log_file;
- $log_created = 0;
-}
-
Amanda::Util::finish_application();