Commits

Palmer, 2E0EOL  committed a822530

Don't download from the master, because we need to reap children.

  • Participants
  • Parent commits 1b109a1
  • Branches develop

Comments (0)

Files changed (1)

 use Getopt::Std;
 use URI::Escape;
 use IO::Interactive qw(is_interactive);
+use POSIX ":sys_wait_h";
 use strict;
 use warnings;
 use diagnostics;
 	}
 
 	foreach my $feedName ( keys(%feeds) ) {
+		my $reaped_pid;
+		my $child_limit_reached = 0;
 		my $feed = $feeds{$feedName};
 		next if ( !$feed->{enable} );
 		next if ( !$feed->{download} );
 				push(@pids, $pid);
 			}
 		} else {
-			warn "Not enough children";
-			Child(\%feeds, $feed);
+			warn "Not enough children, waiting.";
+			$child_limit_reached = 1;
+		}
+
+		if ( $child_limit_reached ) {
+			$reaped_pid = wait();
+		} else {
+			$reaped_pid = waitpid(-1, WNOHANG); # Any children finished?
+			next if ( $reaped_pid <= 0 ); # No, carry on.
+		}
+
+		# A child returned, remove it from the PID list
+		for ( my $i = 0; $i < scalar(@pids); $i++ ) {
+			if ( $pids[$i] == $reaped_pid ) {
+				delete($pids[$i]);
+				last;
+			}
 		}
 	}