summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Fergeau <cfergeau@mandriva.com>2009-10-15 17:44:35 +0000
committerChristophe Fergeau <cfergeau@mandriva.com>2009-10-15 17:44:35 +0000
commit73e7e0ca86cd22631e6cb896801cb3612e32228e (patch)
treebbb99e46b9695f12e5d189c0de214952ba7637f6
parent64f60e96cd8b895cfd908d030d5e6d482b53b98f (diff)
downloadurpmi-73e7e0ca86cd22631e6cb896801cb3612e32228e.tar
urpmi-73e7e0ca86cd22631e6cb896801cb3612e32228e.tar.gz
urpmi-73e7e0ca86cd22631e6cb896801cb3612e32228e.tar.bz2
urpmi-73e7e0ca86cd22631e6cb896801cb3612e32228e.tar.xz
urpmi-73e7e0ca86cd22631e6cb896801cb3612e32228e.zip
print PID of process locking the URPMI database
-rw-r--r--NEWS2
-rw-r--r--urpm/lock.pm22
2 files changed, 23 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index 0001a9f1..7082ba14 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,8 @@
- add --download-all option to download all packages before attempting
to start installation
- fix priviledge escalation in rurpmi and rurpme (#54568)
+- when the database is locked, print the PID of the processus locking it
+ (#38923, Pascal Terjan)
Version 6.29 - 5 October 2009
diff --git a/urpm/lock.pm b/urpm/lock.pm
index 00baec12..687437d3 100644
--- a/urpm/lock.pm
+++ b/urpm/lock.pm
@@ -50,6 +50,18 @@ sub new {
$lock;
}
+sub get_lock_pid {
+ my ($fh) = @_;
+ my ($dev,$ino,undef) = stat($fh);
+ my $major = int($dev/256);
+ my $minor = $dev % 256;
+ my $fileid = sprintf("%02x:%02x:%d",$major,$minor,$ino);
+ open(LOCKS, "/proc/locks") || return;
+ my @locks = <LOCKS>;
+ close(LOCKS);
+ foreach (@locks) { /FLOCK.*WRITE\s*(\d+)\s*$fileid\s/ && return $1 };
+}
+
sub _lock {
my ($lock, $b_exclusive, $b_wait) = @_;
$b_exclusive ||= '';
@@ -63,7 +75,15 @@ sub _lock {
$lock->{info}(N("%s database is locked. Waiting...", $lock->{db_name}));
flock($lock->{fh}, $mode) or $lock->{fatal}(N("aborting"));
} else {
- $lock->{fatal}(N("%s database is locked (another program is already using it)", $lock->{db_name}));
+ my $pid = get_lock_pid($lock->{fh});
+ if($pid) {
+ my $name = urpm::util::cat_("/proc/$pid/cmdline");
+ $name =~ tr/\0/ /;
+ $name =~ s/ *$//;
+ $lock->{fatal}(N("%s database is locked, process %d is already using it", $lock->{db_name}, $pid).($name?" ($name)":""));
+ } else {
+ $lock->{fatal}(N("%s database is locked (another program is already using it)", $lock->{db_name}));
+ }
}
}
$lock->{locked} = 1;