]> git.donarmstrong.com Git - debhelper.git/commitdiff
fix exit status propigation
authorJoey Hess <joey@kitenet.net>
Sun, 17 Jul 2011 20:18:35 +0000 (16:18 -0400)
committerJoey Hess <joey@kitenet.net>
Sun, 17 Jul 2011 20:18:35 +0000 (16:18 -0400)
Also simplified a lot by not special-casing the base case, at the cost of
always forking once.

dh_builddeb

index edb7a751589bee2eec9b31ae39c6772a768c3a3c..df21cc06c8b8744653bc36c650d92ae21198556f 100755 (executable)
@@ -63,56 +63,62 @@ else {
        $dh{FILENAME}="/$dh{FILENAME}";
 }
 
-my $processes=1;
 my $max_procs=1;
 if (defined $ENV{DEB_BUILD_OPTIONS} && $ENV{DEB_BUILD_OPTIONS}=~/parallel=(\d+)/) {
        $max_procs=$1;
 }
 
-foreach my $package (@{$dh{DOPACKAGES}}) {
-       my $pid=0;
+my $processes=1;
+my $exit=0;
+sub reap {
+       if (wait == -1) {
+               $processes=0;
+       }
+       else {
+               $processes--;
+               $exit=1 if $? != 0;
+       }
+}
 
-       if ($max_procs > 1) {
-               while ($processes > $max_procs) {
-                       wait;
-                       $processes--;
-               }
-               $pid=fork();
+foreach my $package (@{$dh{DOPACKAGES}}) {
+       my $pid=fork();
+       if (! defined $pid) {
+               error("fork failed! $!");
+       }
+       $processes++;
+       if ($pid) { # parent
+               reap while $processes > $max_procs;
+               next;
        }
 
-       if ($pid == 0) {
-               my $tmp=tmpdir($package);
-               if (exists $ENV{DH_ALWAYS_EXCLUDE} && length $ENV{DH_ALWAYS_EXCLUDE}) {
-                       if (! compat(5)) {
-                               complex_doit("find $tmp $dh{EXCLUDE_FIND} | xargs rm -rf");
-                       }
-                       else {
-                               # Old broken code here for compatibility. Does not
-                               # remove everything.
-                               complex_doit("find $tmp -name $_ | xargs rm -rf")
-                                       foreach split(":", $ENV{DH_ALWAYS_EXCLUDE});
-                       }
-               }
-               if (! is_udeb($package)) {
-                       doit("dpkg-deb", @{$dh{U_PARAMS}}, "--build", $tmp, $dh{DESTDIR}.$dh{FILENAME});
+       # child
+       my $tmp=tmpdir($package);
+       if (exists $ENV{DH_ALWAYS_EXCLUDE} && length $ENV{DH_ALWAYS_EXCLUDE}) {
+               if (! compat(5)) {
+                       complex_doit("find $tmp $dh{EXCLUDE_FIND} | xargs rm -rf");
                }
                else {
-                       my $filename=$dh{FILENAME};
-                       if (! $filename) {
-                               $filename="/".udeb_filename($package);
-                       }
-                       doit("dpkg-deb", @{$dh{U_PARAMS}}, "--build", $tmp, $dh{DESTDIR}.$filename);
+                       # Old broken code here for compatibility. Does not
+                       # remove everything.
+                       complex_doit("find $tmp -name $_ | xargs rm -rf")
+                               foreach split(":", $ENV{DH_ALWAYS_EXCLUDE});
                }
-               exit (0) if ($max_procs > 1);
+       }
+       if (! is_udeb($package)) {
+               doit("dpkg-deb", @{$dh{U_PARAMS}}, "--build", $tmp, $dh{DESTDIR}.$dh{FILENAME});
        }
        else {
-               if (!defined $pid) {
-                       error("fork failed! $!");
+               my $filename=$dh{FILENAME};
+               if (! $filename) {
+                       $filename="/".udeb_filename($package);
                }
-               $processes++;
+               doit("dpkg-deb", @{$dh{U_PARAMS}}, "--build", $tmp, $dh{DESTDIR}.$filename);
        }
+       exit 0;
 }
-while (($max_procs > 1) && (wait != -1)) {}
+
+reap while $processes;
+exit $exit;
 
 =head1 SEE ALSO