added child reaper
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 1 Sep 2011 14:45:22 +0000 (14:45 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 1 Sep 2011 14:45:22 +0000 (14:45 +0000)
rsync-piper.pl

index fc05140..767ab92 100755 (executable)
@@ -126,12 +126,31 @@ if ( -e $pid_file ) {
                        warn "waiting for rsync to die...\n";
                        sleep 1;
                }
+               
+               open(my $fifo, '<', $log_fifo);
+               while ( kill 0, $pid ) {
+                       my $line = <$fifo>;
+                       warn "<<< $line\n";
+               }
+
                kill 0, $pid && die "can't kill it!";
        } else {
                unlink $pid_file;
        }
 }
 
+use POSIX ":sys_wait_h";
+sub REAPER {
+       my $child;
+       while ((my $waitedpid = waitpid(-1,WNOHANG)) > 0) {
+               warn "reaped $waitedpid" . ($? ? " with exit $?" : '');
+       }
+       $SIG{CHLD} = \&REAPER;  # loathe SysV
+}
+
+$SIG{CHLD} = \&REAPER;
+
+
 if ( ! -e $pid_file ) {
        my $exec = "$rsync --daemon --config $cfg_file --no-detach --port=$port";
        warn "START $exec\n";