Skip to content

Commit

Permalink
make allocpool check the allocations file
Browse files Browse the repository at this point in the history
as sometimes people change allocations, but not the contents of the pool
directory or the other way around. Make it check both, to ensure
someones running mkcloud is not replaced.
  • Loading branch information
JanZerebecki committed Mar 18, 2020
1 parent 21990db commit 2278e4c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions scripts/mkcloudhost/allocpool
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use Time::HiRes qw(sleep);
use Fcntl qw(:DEFAULT :flock);

my $pooldir="$ENV{HOME}/pool";
my $allocationsfile="$ENV{HOME}/allocations";
my $allocname="tmpqueuesched.pid";
# Take the oldest directory
my @dirs= sort { (stat("$a/$allocname"))[9] <=>
Expand All @@ -19,6 +20,19 @@ sleep(rand(2)); # reduce chance of collisions with make -j
# lock+select testdir
my $found=0;
foreach my $d (@dirs) {
# check that allocations isn't out of sync with pool
open my $fha, $allocationsfile or die "Error: cant read $allocationsfile";
my $allocationfound=0;
my $n=$d;
$n=~ s/$pooldir\///;
while(my $line=<$fha>) {
if($line =~ /^[a-z]*$n jenkins$/) {
$allocationfound=1;
last;
}
}
if(!$allocationfound) {die "Error: cant find in $allocationsfile: $n jenkins"}
close($fha);
# use own allocation lock protocol
my $a="$d/$allocname";
sysopen my $fh, $a, O_RDWR|O_CREAT or die "cant create $a";
Expand Down

0 comments on commit 2278e4c

Please sign in to comment.