}
}
+sub worker_thread {
+ my ($name, $thread) = @_;
+
+ my $status;
+ eval {
+ $status = build_package($name, $thread);
+ };
+ if ($@) {
+ warning("$@");
+ $status = -1;
+ }
+
+ {
+ lock($DETACHING);
+ threads->detach() if ! threads->is_detached();
+ @running = grep { $_ ne "$name"} @running;
+ push(@done, $name);
+ if ($status == 0) {
+ $dirty = 1;
+ } else {
+ push @errors, "$name-$dist-$arch";
+ }
+ }
+
+ debug("*** build $name exit with status($status), is dirty:$dirty, (worker: $thread) ***");
+ return $status;
+}
+
sub build_package {
my ($name, $thread) = @_;
use vars qw(@package_repos);
{
lock ($DETACHING);
if ($TERM == 1 || my_system("sudo -v") != 0) {
- threads->detach() if ! threads->is_detached();
return -1;
}
}
push @args, "--clean";
push @args, $redirect;
$cmd = join(" ", @args);
- if (my_system($cmd) != 0) {
- threads->detach() if ! threads->is_detached();
- return -1;
- }
+ return -1 if (my_system($cmd) != 0);
} else {
info("build directory does not exist");
}
$mount = "sudo umount $scratch/home/abuild/rpmbuild/BUILD/$name-$version";
my_system($mount);
- # Detach and terminate
- {
- lock($DETACHING);
- threads->detach() if ! threads->is_detached();
- $dirty = 1;
- @running = grep { $_ ne "$name"} @running;
- push(@done, $name);
- }
info("finished incremental building $name");
info("building log can be found here: $scratch/.build.log");
$packages_built = 1;
my_system("echo D: >> $order_dir/.repo.cache.local");
# Merge local repo catch and remote repo cache
my_system("cat $order_dir/.repo.cache.local $order_dir/.repo.cache.remote >$order_dir/.repo.cache");
- $dirty = 1;
- threads->detach() if ! threads->is_detached();
- @running = grep { $_ ne "$name"} @running;
- push(@done, $name);
}
info("finished building $name");
$packages_built = 1;
- return(0);
+ return 0;
} else {
mkdir_p "$localrepo/$dist/$arch/logs/fail/$name-$version-$release";
if ( -f "$scratch/.build.log" ) {
my_system ("sudo rm -f $scratch/.build.log");
warning("build failed, Leaving the logs in $localrepo/$dist/$arch/logs/fail/$name-$version-$release/log");
}
- # Detach and terminate
- {
- lock($DETACHING);
- threads->detach() if ! threads->is_detached();
- @running = grep { $_ ne "$name"} @running;
- push(@done, $name);
- push @errors, "$name-$dist-$arch";
- }
return 1;
}
last if (! $job);
my $worker = find_idle();
- my $thr = threads->create('build_package',$job, $worker);
+ my $thr = threads->create(\&worker_thread, $job, $worker);
my $tid = $thr->tid();
push (@running, $job);
set_busy($worker, $tid);