Update of /cvsroot/fink/fink/perlmod/Fink In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2952
Modified Files: ChangeLog Engine.pm Package.pm PkgVersion.pm Log Message: Add master lock to be used whenever changing buildlocks. 'fink cleanup --bl' only attempts to remove lockpkgs that are installed. Index: PkgVersion.pm =================================================================== RCS file: /cvsroot/fink/fink/perlmod/Fink/PkgVersion.pm,v retrieving revision 1.479 retrieving revision 1.480 diff -u -d -r1.479 -r1.480 --- PkgVersion.pm 12 Oct 2005 02:17:38 -0000 1.479 +++ PkgVersion.pm 12 Oct 2005 05:31:47 -0000 1.480 @@ -4070,7 +4070,8 @@ print "Setting runtime build-lock...\n"; - # use flock to get an exlusive lock for the the %n-%v-%r + # get an exlusive lock for the the %n-%v-%r + Fink::Package->control_buildlocks(1); my $lockdir = "$basepath/var/run/fink/buildlock"; mkdir_p $lockdir or die "can't create $lockdir directory for buildlocks\n"; @@ -4081,7 +4082,10 @@ # bootstrapping occurs before we have package-management tools # needed for buildlock package so don't create one - return if $self->{_bootstrap}; + if ($self->{_bootstrap}) { + Fink::Package->control_buildlocks(0); + return; + } my $pkgname = $self->get_name(); my $pkgvers = $self->get_fullversion(); @@ -4188,6 +4192,8 @@ die "buildlock failure\n" if $lock_failed; + Fink::Package->control_buildlocks(0); + # record buildlock package name so we can remove it during clear_buildkock $self->{_lockpkg} = $lockpkg; } @@ -4203,6 +4209,8 @@ return $self->get_parent->clear_buildlock(); } + Fink::Package->control_buildlocks(0); + if (exists $self->{_lockpkg}) { print "Removing build-lock package...\n"; my $lockpkg = $self->{_lockpkg}; @@ -4224,6 +4232,8 @@ unlink $self->{_lockfile}->[0]; # try to clean up delete $self->{_lockfile}; } + + Fink::Package->control_buildlocks(0); } =item ensure_gpp_prefix Index: Package.pm =================================================================== RCS file: /cvsroot/fink/fink/perlmod/Fink/Package.pm,v retrieving revision 1.162 retrieving revision 1.163 diff -u -d -r1.162 -r1.163 --- Package.pm 8 Sep 2005 06:16:15 -0000 1.162 +++ Package.pm 12 Oct 2005 05:31:47 -0000 1.163 @@ -50,6 +50,9 @@ our @essential_packages = (); our $essential_valid = 0; +# control of the buildlock system +our $buildlock_master = undef; + END { } # module clean-up code here (global destructor) =head1 NAME @@ -1237,6 +1240,38 @@ } } +=item control_buildlocks + + Fink::Package->control_buildlocks(1); + # add or remove buildlocks + Fink::Package->control_buildlocks(0); + +When called with a boolean "true" value, get an exclusive lock on the +buildlock system. When called with a boolean "false" value, release +this exclusive lock. You must have this exclusive lock whenever you +will be setting or clearing buildlocks (or if you want to prevent +other fink processes from doing so for any reason). + +=cut + +sub control_buildlocks { + my $class = shift; + my $lock = shift || 0; + + if ($lock) { + if (!defined $buildlock_master) { + # no use relocking if we already own the lock + my $lockdir = "$basepath/var/run/fink/buildlock"; + mkdir_p $lockdir or + die "can't create $lockdir directory for master buildlock\n"; + my $lockfile = "$lockdir/MASTER_LOCK"; + $buildlock_master = lock_wait($lockfile, exclusive => 1); + } + } else { + undef $buildlock_master; + } +} + =back =cut Index: Engine.pm =================================================================== RCS file: /cvsroot/fink/fink/perlmod/Fink/Engine.pm,v retrieving revision 1.331 retrieving revision 1.332 diff -u -d -r1.331 -r1.332 --- Engine.pm 12 Oct 2005 02:17:38 -0000 1.331 +++ Engine.pm 12 Oct 2005 05:31:47 -0000 1.332 @@ -1351,7 +1351,7 @@ sub cleanup_buildlocks { my %opts = (dryrun => 0, @_); - # gather all .pid files + Fink::Package->control_buildlocks(1); print "Reading buildlocks...\n"; my $lockdir = "$basepath/var/run/fink/buildlock"; @@ -1362,44 +1362,52 @@ close $dirhandle; } else { print "Warning: could not read buildlock directory $lockdir: $!\n"; + Fink::Package->control_buildlocks(0); return 0; } if ([EMAIL PROTECTED]) { print "No buildlocks found\n"; + Fink::Package->control_buildlocks(0); return 0; } my $locks_left = 0; - my %lockpkgs = (); + my %lock_FHs = (); + my @lock_pkgs = (); foreach my $lockfile (sort @lockfiles) { my ($fullname) = $lockfile =~ /^(.+)\.lock$/; my $lock_FH = lock_wait("$lockdir/$lockfile", exclusive => 1, no_block => 1); if ($lock_FH) { # got flock so buildlock is not in use if ($opts{dryrun}) { - print "Buildlock for $fullname is dead.\n"; + print "Runtime buildlock for $fullname is dead.\n"; } else { - print "Buildlock for $fullname is dead...will clear\n"; - $lockpkgs{$fullname} = $lock_FH; + print "Runtime buildlock for $fullname is dead...will clear.\n"; + $lock_FHs{"$lockdir/$lockfile"} = $lock_FH; + } + if (-e "$lockdir/$fullname.pid") { + print "...and its lock package too.\n"; + push @lock_pkgs, "fink-buildlock-$fullname" if !$opts{dryrun}; } } else { print "Buildlock for $fullname is still in use.\n"; - $locks_left++; + $locks_left = 1; } } - my @lockpkgs = sort keys %lockpkgs; - if (@lockpkgs) { - # found dead locks and we are not dry-run... - print "Clearing " . scalar @lockpkgs . " dead buildlock(s)...\n"; - # remove lock packages - Fink::PkgVersion::phase_deactivate(map "fink-buildlock-$_", @lockpkgs); - print "...and removing the dead runtime lockfiles...\n"; - rm_f map "$lockdir/$_.lock", @lockpkgs; + if (@lock_pkgs) { + printf "Removing %i dead buildlock package(s)...\n", scalar @lock_pkgs; + Fink::PkgVersion::phase_deactivate(@lock_pkgs); # doesn't return if failure } - # cleanup's runtime locks go away when %lockpkgs goes out of scope... + if (%lock_FHs) { + printf "Removing %i dead lockfile(s)...\n", scalar keys %lock_FHs; + rm_f keys %lock_FHs or $locks_left = 1; + %lock_FHs = (); + } + + Fink::Package->control_buildlocks(0); return $locks_left; } Index: ChangeLog =================================================================== RCS file: /cvsroot/fink/fink/perlmod/Fink/ChangeLog,v retrieving revision 1.1166 retrieving revision 1.1167 diff -u -d -r1.1166 -r1.1167 --- ChangeLog 12 Oct 2005 02:17:38 -0000 1.1166 +++ ChangeLog 12 Oct 2005 05:31:47 -0000 1.1167 @@ -1,3 +1,10 @@ +2005-10-12 Daniel Macks <[EMAIL PROTECTED]> + + * Engine.pm, Package.pm, PkgVersion.pm: New Package::control_buildlocks + class method used to control access to whole buildlock system. + * Engine.pm: During buildlock cleanup, only remove lockpkgs that + are installed (indicated by presence of their .pid files). + 2005-10-11 Daniel Macks <[EMAIL PROTECTED]> * PkgVersion.pm: Add a flock-based outer layer around the ------------------------------------------------------- This SF.Net email is sponsored by: Power Architecture Resource Center: Free content, downloads, discussions, and more. http://solutions.newsforge.com/ibmarch.tmpl _______________________________________________ Fink-commits mailing list Fink-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/fink-commits