summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2006-11-23 08:33:45 +0000
committerPascal Rigaux <pixel@mandriva.com>2006-11-23 08:33:45 +0000
commit60d85b7e9fe14eeff84053cc1585ca45eaa3f1ab (patch)
treed20074bef1523c17e8b69e39099ad7c9e5f7e4ec
parenta331f6da8a7d9384093c1b3a95a682fd9a2e98be (diff)
downloadurpmi-60d85b7e9fe14eeff84053cc1585ca45eaa3f1ab.tar
urpmi-60d85b7e9fe14eeff84053cc1585ca45eaa3f1ab.tar.gz
urpmi-60d85b7e9fe14eeff84053cc1585ca45eaa3f1ab.tar.bz2
urpmi-60d85b7e9fe14eeff84053cc1585ca45eaa3f1ab.tar.xz
urpmi-60d85b7e9fe14eeff84053cc1585ca45eaa3f1ab.zip
don't have a global variable to hold locks, otherwise code can't lock twice
non-exclusive
-rwxr-xr-xgurpmi210
-rw-r--r--urpm.pm12
-rw-r--r--urpm/media.pm13
-rw-r--r--urpm/sys.pm32
-rwxr-xr-xurpmf6
-rwxr-xr-xurpmi9
-rwxr-xr-xurpmq12
7 files changed, 42 insertions, 52 deletions
diff --git a/gurpmi2 b/gurpmi2
index 488753fb..300034aa 100755
--- a/gurpmi2
+++ b/gurpmi2
@@ -91,6 +91,8 @@ my @ask_unselect = urpm::select::unselected_packages($urpm, $state);
$mainw->show_all;
Gtk2->main;
+my ($rpm_lock, $urpmi_lock);
+
#- Creates and configure an urpm object for this application to use.
sub configure_urpm() {
my $urpm = new urpm;
@@ -119,8 +121,8 @@ sub configure_urpm() {
$w->run;
$w->destroy;
};
- urpm::sys::lock_rpm_db($urpm, 'exclusive');
- urpm::sys::lock_urpmi_db($urpm);
+ $rpm_lock = urpm::sys::lock_rpm_db($urpm, 'exclusive');
+ $urpmi_lock = urpm::sys::lock_urpmi_db($urpm);
urpm::media::configure($urpm,
root => $gurpmi::options{root},
media => $gurpmi::options{media},
@@ -337,7 +339,7 @@ sub do_install_3 () {
} else {
$progress_label->set_label(N("Installation finished"));
}
- urpm::sys::unlock_urpmi_db($urpm);
- urpm::sys::unlock_rpm_db($urpm);
+ urpm::sys::unlock($urpmi_lock);
+ urpm::sys::unlock($rpm_lock);
urpm::removable::try_umounting_removables($urpm);
}
diff --git a/urpm.pm b/urpm.pm
index d1c1d649..4f43f45c 100644
--- a/urpm.pm
+++ b/urpm.pm
@@ -13,7 +13,7 @@ use urpm::cfg;
use urpm::md5sum;
use MDV::Distribconf;
-our $VERSION = '4.8.29';
+our $VERSION = '4.9.0';
our @ISA = qw(URPM Exporter);
our @EXPORT_OK = 'file_from_local_url';
@@ -175,20 +175,14 @@ sub download_source_packages {
my %error_sources;
require urpm::get_pkgs;
- urpm::sys::lock_urpmi_db($urpm, 'exclusive') if !$options{nolock};
+ my $lock = !$options{nolock} && urpm::sys::lock_urpmi_db($urpm, 'exclusive');
urpm::removable::copy_packages_of_removable_media($urpm, $list, \%sources, $options{ask_for_medium}) or return;
urpm::get_pkgs::download_packages_of_distant_media($urpm, $list, \%sources, \%error_sources, %options);
- urpm::sys::unlock_urpmi_db($urpm) unless $options{nolock};
+ $lock and urpm::sys::unlock($lock);
%sources, %error_sources;
}
-#- deprecated
-sub exlock_urpmi_db {
- my ($urpm) = @_;
- urpm::sys::lock_urpmi_db($urpm, 'exclusive');
-}
-
#- extract package that should be installed instead of upgraded,
#- sources is a hash of id -> source rpm filename.
sub extract_packages_to_install {
diff --git a/urpm/media.pm b/urpm/media.pm
index 68665f1a..c55fb786 100644
--- a/urpm/media.pm
+++ b/urpm/media.pm
@@ -600,7 +600,7 @@ sub add_medium {
#- make sure configuration has been read.
$urpm->{media} or die "caller should have used ->read_config or ->configure first";
- urpm::sys::lock_urpmi_db($urpm, 'exclusive') if !$options{nolock};
+ my $lock = urpm::sys::lock_urpmi_db($urpm, 'exclusive');
#- if a medium with that name has already been found, we have to exit now
my $medium;
@@ -643,7 +643,7 @@ sub add_medium {
$urpm->{log}(N("added medium %s", $name));
$urpm->{modified} = 1;
- $options{nolock} or urpm::sys::unlock_urpmi_db($urpm);
+ $lock and urpm::sys::unlock($lock);
$name;
}
@@ -1710,12 +1710,13 @@ sub update_media {
$options{nopubkey} ||= $urpm->{options}{nopubkey};
#- get gpg-pubkey signature.
+ my $rpm_lock;
if (!$options{nopubkey}) {
- urpm::sys::lock_rpm_db($urpm, 'exclusive');
+ $rpm_lock = urpm::sys::lock_rpm_db($urpm, 'exclusive');
$urpm->{keys} or $urpm->parse_pubkeys(root => $urpm->{root});
}
#- lock database if allowed.
- urpm::sys::lock_urpmi_db($urpm, 'exclusive') if !$options{nolock};
+ my $urpmi_lock = urpm::sys::lock_urpmi_db($urpm, 'exclusive') if !$options{nolock};
#- examine each medium to see if one of them needs to be updated.
#- if this is the case and if not forced, try to use a pre-calculated
@@ -1766,8 +1767,8 @@ sub update_media {
write_MD5SUM($urpm);
}
- $options{nolock} or urpm::sys::unlock_urpmi_db($urpm);
- $options{nopubkey} or urpm::sys::unlock_rpm_db($urpm);
+ $urpmi_lock and urpm::sys::unlock($urpmi_lock);
+ $rpm_lock and urpm::sys::unlock($rpm_lock);
}
#- clean params and depslist computation zone.
diff --git a/urpm/sys.pm b/urpm/sys.pm
index e1d83f20..dd24b08e 100644
--- a/urpm/sys.pm
+++ b/urpm/sys.pm
@@ -194,7 +194,7 @@ sub clean_dir {
# - lock rpm db in chroot
# - lock urpmi db in /
sub _lock {
- my ($urpm, $fh_ref, $file, $b_exclusive) = @_;
+ my ($urpm, $file, $b_exclusive) = @_;
#- avoid putting a require on Fcntl ':flock' (which is perl and not perl-base).
my ($LOCK_SH, $LOCK_EX, $LOCK_NB) = (1, 2, 4);
if ($b_exclusive) {
@@ -206,39 +206,31 @@ sub _lock {
#- lock urpmi database, if the LOCK file doesn't exists no share lock.
}
my ($sense, $mode) = $b_exclusive ? ('>', $LOCK_EX) : ('<', $LOCK_SH);
- open $$fh_ref, $sense, $file or return;
- flock $$fh_ref, $mode|$LOCK_NB or $urpm->{fatal}(7, N("urpmi database locked"));
+ open(my $fh, $sense, $file) or return;
+ flock $fh, $mode|$LOCK_NB or $urpm->{fatal}(7, N("urpmi database locked"));
+# warn "locking $file $b_exclusive ($fh)\n";
+ $fh;
}
-my $RPMLOCK_FILE;
-my $LOCK_FILE;
-
sub lock_rpm_db {
my ($urpm, $b_exclusive) = @_;
- _lock($urpm, \$RPMLOCK_FILE, "$urpm->{root}/$urpm->{statedir}/.RPMLOCK", $b_exclusive);
+ _lock($urpm, "$urpm->{root}/$urpm->{statedir}/.RPMLOCK", $b_exclusive);
}
sub lock_urpmi_db {
my ($urpm, $b_exclusive) = @_;
- _lock($urpm, \$LOCK_FILE, "$urpm->{statedir}/.LOCK", $b_exclusive);
+ _lock($urpm, "$urpm->{statedir}/.LOCK", $b_exclusive);
}
-sub _unlock {
- my ($fh_ref) = @_;
+sub unlock {
+ my ($fh) = @_;
+# warn "unlocking $fh\n";
#- avoid putting a require on Fcntl ':flock' (which is perl and not perl-base).
my $LOCK_UN = 8;
#- now everything is finished.
#- release lock on database.
- flock $$fh_ref, $LOCK_UN;
- close $$fh_ref;
-}
-sub unlock_rpm_db {
- my ($_urpm) = @_;
- _unlock(\$RPMLOCK_FILE);
-}
-sub unlock_urpmi_db {
- my ($_urpm) = @_;
- _unlock(\$LOCK_FILE);
+ flock $fh, $LOCK_UN;
+ close $fh;
}
sub syserror {
diff --git a/urpmf b/urpmf
index 2ca63804..7feb8b90 100755
--- a/urpmf
+++ b/urpmf
@@ -190,12 +190,12 @@ if ($env) {
$urpm->{statedir} = $env;
}
-{
+my $lock = do {
#- lock to avoid concurrent media updates,
#- but don't die if it doesn't work
local $urpm->{fatal} = sub { printf STDERR "%s\n", $_[1] };
urpm::sys::lock_urpmi_db($urpm);
-}
+};
my $need_hdlist = grep { $usedtags{$_} } qw(
buildhost
buildtime
@@ -219,7 +219,7 @@ urpm::media::configure($urpm,
callback => $callback,
need_hdlist => $need_hdlist,
);
-urpm::sys::unlock_urpmi_db($urpm);
+urpm::sys::unlock($lock);
if ($need_hdlist) {
# @hdmedia is the list of all media searched that use hdlists
diff --git a/urpmi b/urpmi
index 40916d4e..767de487 100755
--- a/urpmi
+++ b/urpmi
@@ -334,9 +334,10 @@ if (exists $urpm->{options}{'priority-upgrade'} && $urpm->{options}{'priority-up
unlink glob('/var/lib/rpm/__db.*') unless $root;
}
+my ($rpm_lock, $urpmi_lock);
unless ($env || $nolock) {
- urpm::sys::lock_rpm_db($urpm, 'exclusive');
- urpm::sys::lock_urpmi_db($urpm);
+ $rpm_lock = urpm::sys::lock_rpm_db($urpm, 'exclusive');
+ $urpmi_lock = urpm::sys::lock_urpmi_db($urpm);
}
#- should we ignore arch compatibility
@@ -825,8 +826,8 @@ if ($nok) {
}
unless ($env || $nolock) {
- urpm::sys::unlock_urpmi_db($urpm);
- urpm::sys::unlock_rpm_db($urpm);
+ urpm::sys::unlock($urpmi_lock);
+ urpm::sys::unlock($rpm_lock);
#- try to umount removable device which may have been mounted.
urpm::removable::try_umounting_removables($urpm);
diff --git a/urpmq b/urpmq
index a5dee31d..f4b4c78d 100755
--- a/urpmq
+++ b/urpmq
@@ -138,9 +138,10 @@ if ($urpm::args::options{env}) {
#- should we ignore arch compatibility
if ($urpm::args::options{ignorearch}) { urpm::shunt_ignorearch() }
-$urpm::args::options{upgrade} && !$urpm::args::options{env} && !$urpm::args::options{nolock}
- and urpm::sys::lock_rpm_db($urpm);
-urpm::sys::lock_urpmi_db($urpm) if !$urpm::args::options{nolock};
+my $rpm_lock =
+ $urpm::args::options{upgrade} && !$urpm::args::options{env} && !$urpm::args::options{nolock}
+ && urpm::sys::lock_rpm_db($urpm);
+my $urpmi_lock = !$urpm::args::options{nolock} && urpm::sys::lock_urpmi_db($urpm);
urpm::media::configure($urpm,
nocheck_access => 1,
nodepslist => $urpm::args::options{nodepslist},
@@ -427,9 +428,8 @@ if ($urpm::args::options{list_aliases}) {
exit 0;
}
}
-$urpm::args::options{nolock} or urpm::sys::unlock_urpmi_db($urpm);
-$urpm::args::options{upgrade} && !$urpm::args::options{env} && !$urpm::args::options{nolock}
- and urpm::sys::unlock_rpm_db($urpm);
+$urpmi_lock and urpm::sys::unlock($urpmi_lock);
+$rpm_lock and urpm::sys::unlock($rpm_lock);
#- print sub for query.
my $query_sub = sub {