Imported Upstream version 3.3.3
[debian/amanda] / server-src / amrmtape.pl
index f7d37081a4c60ade7f8adc7651a4d0534d86f09c..2f9ec576cfab3517e7632407439a3138fab86ca0 100644 (file)
@@ -2,9 +2,10 @@
 #
 # 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
@@ -47,26 +48,6 @@ my $changer_name;
 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
@@ -149,26 +130,6 @@ if ($cfgerr_level >= $CFGERR_WARNINGS) {
 }
 
 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)
@@ -208,11 +169,12 @@ my $scrub_db = sub {
         $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]";
@@ -294,11 +256,6 @@ my $scrub_db = sub {
 
 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,
@@ -349,9 +306,4 @@ my $erase_volume = make_cb('erase_volume' => sub {
 $erase_volume->();
 Amanda::MainLoop::run();
 
-if ($log_created == 1) {
-    unlink $log_file;
-    $log_created = 0;
-}
-
 Amanda::Util::finish_application();