- if ( $xfer->getStats->{fileCnt} == 1 ) {
- #
- # Make sure it is still the machine we expect. We do this while
- # the transfer is running to avoid a potential race condition if
- # the ip address was reassigned by dhcp just before we started
- # the transfer.
- #
- if ( my $errMsg = CorrectHostCheck($hostIP, $host) ) {
- $stat{hostError} = $errMsg;
- last SCAN;
- }
+ #
+ # The parent must close the write handle since BackupPC_tarCreate
+ # is using it.
+ #
+ close(WH);
+
+ $xferPid = $xfer->xferPid;
+ print(LOG $bpc->timeStamp, $logMsg, " (tarPid=$tarPid, xferPid=$xferPid)\n");
+ print("started restore, tarPid=$tarPid, xferPid=$xferPid\n");
+
+ #
+ # Parse the output of the transfer program and BackupPC_tarCreate
+ # while they run. Since we are reading from two or more children
+ # we use a select.
+ #
+ my($FDread, $tarOut, $mesg);
+ vec($FDread, fileno(TAR), 1) = 1;
+ $xfer->setSelectMask(\$FDread);
+
+ SCAN: while ( 1 ) {
+ my $ein = $FDread;
+ last if ( $FDread =~ /^\0*$/ );
+ alarm($Conf{ClientTimeout});
+ select(my $rout = $FDread, undef, $ein, undef);
+ if ( vec($rout, fileno(TAR), 1) ) {
+ if ( sysread(TAR, $mesg, 8192) <= 0 ) {
+ vec($FDread, fileno(TAR), 1) = 0;
+ if ( !close(TAR) ) {
+ $tarCreateErrCnt = 1;
+ $tarCreateErr = "BackupPC_tarCreate failed";
+ }
+ } else {
+ $tarOut .= $mesg;
+ }
+ }
+ while ( $tarOut =~ /(.*?)[\n\r]+(.*)/s ) {
+ $_ = $1;
+ $tarOut = $2;
+ $RestoreLOG->write(\"tarCreate: $_\n");
+ if ( /^Done: (\d+) files, (\d+) bytes, (\d+) dirs, (\d+) specials, (\d+) errors/ ) {
+ $tarCreateFileCnt = $1;
+ $tarCreateByteCnt = $2;
+ $tarCreateErrCnt = $5;
+ }
+ }
+ last if ( !$xfer->readOutput(\$FDread, $rout) );
+ while ( my $str = $xfer->logMsgGet ) {
+ print(LOG $bpc->timeStamp, "xfer: $str\n");
+ }
+ if ( $xfer->getStats->{fileCnt} == 1 ) {
+ #
+ # Make sure it is still the machine we expect. We do this while
+ # the transfer is running to avoid a potential race condition if
+ # the ip address was reassigned by dhcp just before we started
+ # the transfer.
+ #
+ if ( my $errMsg = CorrectHostCheck($hostIP, $host) ) {
+ $stat{hostError} = $errMsg;
+ last SCAN;
+ }
+ }