* Split BackupPC_Admin into a set of modules, one for each major action.
[BackupPC.git] / bin / BackupPC_dump
index e6d75f3..79393bf 100755 (executable)
@@ -52,7 +52,7 @@
 #   Craig Barratt  <cbarratt@users.sourceforge.net>
 #
 # COPYRIGHT
-#   Copyright (C) 2001  Craig Barratt
+#   Copyright (C) 2001-2003  Craig Barratt
 #
 #   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
 #
 #========================================================================
 #
-# Version 2.0.0beta1, released 30 Mar 2003.
+# Version 2.1.0_CVS, released 3 Jul 2003.
 #
 # See http://backuppc.sourceforge.net.
 #
 #========================================================================
 
 use strict;
+no  utf8;
 use lib "/usr/local/BackupPC/lib";
 use BackupPC::Lib;
 use BackupPC::FileZIO;
 use BackupPC::Xfer::Smb;
 use BackupPC::Xfer::Tar;
 use BackupPC::Xfer::Rsync;
+use Socket;
 use File::Path;
 use Getopt::Std;
 
@@ -146,7 +148,8 @@ if ( $opts{d} ) {
     $Hosts = $bpc->HostInfoRead($client);
 }
 if ( !defined($Hosts->{$client}) ) {
-    print("Exiting because host $client does not exist in the hosts file\n");
+    print("Exiting because host $client does not exist in the hosts file\n")
+                           if ( $opts{v} );
     exit(1)
 }
 
@@ -215,9 +218,8 @@ if ( !$opts{d} ) {
        print("Name server doesn't know about $host; trying NetBios\n")
                        if ( $opts{v} );
         if ( !defined($hostIP = $bpc->NetBiosHostIPFind($host)) ) {
-           print(LOG $bpc->timeStamp,
-                           "dump failed: Can't find host $host\n");
-            print("dump failed: Can't find host $host\n");
+           print(LOG $bpc->timeStamp, "Can't find host $host via netbios\n");
+            print("host not found\n");
             exit(1);
         }
     } else {
@@ -446,12 +448,22 @@ for my $shareName ( @$ShareNames ) {
        # This xfer method outputs a tar format file, so we start a
        # BackupPC_tarExtract to extract the data.
        #
-       # Create a pipe to connect the Xfer method to BackupPC_tarExtract
+       # Create a socketpair to connect the Xfer method to BackupPC_tarExtract
        # WH is the write handle for writing, provided to the transport
-       # program, and RH is the other end of the pipe for reading,
+       # program, and RH is the other end of the socket for reading,
        # provided to BackupPC_tarExtract.
        #
-       pipe(RH, WH);
+        if ( socketpair(RH, WH, AF_UNIX, SOCK_STREAM, PF_UNSPEC) ) {
+           shutdown(RH, 1);    # no writing to this socket
+           shutdown(WH, 0);    # no reading from this socket
+           setsockopt(RH, SOL_SOCKET, SO_RCVBUF, 8 * 65536);
+           setsockopt(WH, SOL_SOCKET, SO_SNDBUF, 8 * 65536);
+       } else {
+           #
+           # Default to pipe() if socketpair() doesn't work.
+           #
+           pipe(RH, WH);
+       }
 
        #
        # fork a child for BackupPC_tarExtract.  TAR is a file handle
@@ -465,6 +477,7 @@ for my $shareName ( @$ShareNames ) {
            close(WH);
            last;
        }
+       binmode(TAR);
        if ( !$tarPid ) {
            #
            # This is the tar child.  Close the write end of the pipe,
@@ -491,6 +504,7 @@ for my $shareName ( @$ShareNames ) {
        open(NEW_FILES, ">", "$TopDir/pc/$client/NewFileList")
                     || die("can't open $TopDir/pc/$client/NewFileList");
        $newFilesFH = *NEW_FILES;
+       binmode(NEW_FILES);
     }
 
     #
@@ -601,7 +615,7 @@ for my $shareName ( @$ShareNames ) {
                # the transfer.
                #
                if ( my $errMsg = CorrectHostCheck($hostIP, $host) ) {
-                   $stat{hostError} = $errMsg;
+                   $stat{hostError} = $errMsg if ( $stat{hostError} eq "" );
                    last SCAN;
                }
            }
@@ -808,7 +822,12 @@ sub catch_signal
     my $fileExt = $Conf{CompressLevel} > 0 ? ".z" : "";
 
     #
-    # Ignore signals in children
+    # Children quit quietly on ALRM
+    #
+    exit(1) if ( $Pid != $$ && $signame eq "ALRM" );
+
+    #
+    # Ignore other signals in children
     #
     return if ( $Pid != $$ );
 
@@ -977,7 +996,7 @@ sub UserCommandRun
         LOG        => *LOG,
         XferLOG    => $XferLOG,
         stat       => \%stat,
-        xferOK     => $stat{xferOK},
+        xferOK     => $stat{xferOK} || 0,
        type       => $type,
     };
     my $cmd = $bpc->cmdVarSubstitute($Conf{$type}, $vars);