summaryrefslogtreecommitdiff
path: root/dh_builddeb
diff options
context:
space:
mode:
Diffstat (limited to 'dh_builddeb')
-rwxr-xr-xdh_builddeb74
1 files changed, 40 insertions, 34 deletions
diff --git a/dh_builddeb b/dh_builddeb
index edb7a75..df21cc0 100755
--- a/dh_builddeb
+++ b/dh_builddeb
@@ -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