BackupPC-users

[BackupPC-users] Patch to fork parity generation to allow alarm to be refreshed (Was: Re: Parity (par2) command running on archives even though set to 0)

2012-04-03 15:24:34
Subject: [BackupPC-users] Patch to fork parity generation to allow alarm to be refreshed (Was: Re: Parity (par2) command running on archives even though set to 0)
From: Timothy J Massey <tmassey AT obscorp DOT com>
To: "General list for user discussion, questions and support" <backuppc-users AT lists.sourceforge DOT net>
Date: Tue, 3 Apr 2012 14:59:57 -0400
Timothy J Massey <tmassey AT obscorp DOT com> wrote on 03/20/2012 05:25:30 PM:

> One thought would be to fork the parity (and tar) command and open
> the output of the command from the parent, and let the parent both
> add the output to the log file as well as update the alarm.  I have
> some tiny experience with this (mainly boiler-plate code).  Would
> such a change be at least theoretically acceptable to being included
> as a patch?  I don't want to make such a change without it being
> possibly included upstream:  I don't like the idea of depending on
> it in the future without that.

Well, I got no reply, but I went ahead and did it.  I would greatly appreciate comments on this.  Ideally, I would love to see this added to BackupPC.

Tim Massey
 
Out of the Box Solutions, Inc.
Creative IT Solutions Made Simple!

http://www.OutOfTheBoxSolutions.com
tmassey AT obscorp DOT com
      22108 Harper Ave.
St. Clair Shores, MI 48080
Office: (800)750-4OBS (4627)
Cell: (586)945-8796



--- BackupPC_archiveHost.org    2012-01-22 21:52:31.000000000 -0500
+++ BackupPC_archiveHost.new    2012-04-03 12:32:53.850060836 -0400
@@ -157,11 +157,37 @@ if ( -d $outLoc && -x $parPath ) {
     if ( length($parfile) ) {
         print("Running $parPath to create parity files\n");
        my $parCmd = "$parPath c -r$parfile $outLocE/$host.$bkupNum.tar$fileExt.par2 $outLocE/$host.$bkupNum.tar$fileExt*";
-        $ret = system($parCmd);
-        if ( $ret ) {
+
+        # Forking parity command so that we can reset alarm
+        my $child;
+        if (not defined($child = open(INPUTFILE, "-|"))) {
+            print("Could not fork:  $!\n");
+            print("Error:  $parPath failed\n");
+            exit(1);
+        }
+        if ($child) {
+            # Parent process - do nothing here
+        } else {
+            # Child process:  execute command and exit
+            system($parCmd);
+            exit $?;
+        }
+        # Child exited above, so if we're here, we're the parent...
+
+        # Start processing the output of our child:
+        my $parOutput;
+        while ( read(INPUTFILE, $parOutput, 1) ) {
+            # The parity program has output something:  reset alrm
+            alarm 0;
+            # If you want to process the output in some way, do it here
+            print $parOutput;
+        }
+        if ( $? ) {
            print("Executing: $parCmd\n");
             print("Error: $parPath failed\n");
             exit(1);
         }
+        close(INPUTFILE);
+        # End processing child output
     }
 }
------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second 
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
_______________________________________________
BackupPC-users mailing list
BackupPC-users AT lists.sourceforge DOT net
List:    https://lists.sourceforge.net/lists/listinfo/backuppc-users
Wiki:    http://backuppc.wiki.sourceforge.net
Project: http://backuppc.sourceforge.net/
<Prev in Thread] Current Thread [Next in Thread>
  • [BackupPC-users] Patch to fork parity generation to allow alarm to be refreshed (Was: Re: Parity (par2) command running on archives even though set to 0), Timothy J Massey <=