diff options
author | Thierry Vignaud <tv@mageia.org> | 2012-01-06 19:43:50 +0000 |
---|---|---|
committer | Thierry Vignaud <tv@mageia.org> | 2012-01-06 19:43:50 +0000 |
commit | 94ead5c886348823bab7f1c33abdb4bad368d7b2 (patch) | |
tree | ed0105c5699aa55a9a7cd321ac36143c46fa45ea /urpm/lock.pm | |
parent | f27491aa20c8e3b76cf4684de79ae553f9d207f0 (diff) | |
download | urpmi-94ead5c886348823bab7f1c33abdb4bad368d7b2.tar urpmi-94ead5c886348823bab7f1c33abdb4bad368d7b2.tar.gz urpmi-94ead5c886348823bab7f1c33abdb4bad368d7b2.tar.bz2 urpmi-94ead5c886348823bab7f1c33abdb4bad368d7b2.tar.xz urpmi-94ead5c886348823bab7f1c33abdb4bad368d7b2.zip |
(warn_about_locker) split it out of _lock()
Diffstat (limited to 'urpm/lock.pm')
-rw-r--r-- | urpm/lock.pm | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/urpm/lock.pm b/urpm/lock.pm index 28967137..2e2de87a 100644 --- a/urpm/lock.pm +++ b/urpm/lock.pm @@ -59,6 +59,18 @@ sub get_lock_pid { foreach (urpm::util::cat_('/proc/locks')) { /FLOCK.*WRITE\s*(\d+)\s*$fileid\s/ && return $1 } } +sub warn_about_locker { + my ($lock) = @_; + if (my $pid = get_lock_pid($lock->{fh})) { + 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})); + } +} + sub _lock { my ($lock, $b_exclusive, $b_wait) = @_; $b_exclusive ||= ''; @@ -72,15 +84,7 @@ sub _lock { $lock->{info}(N("%s database is locked. Waiting...", $lock->{db_name})); flock($lock->{fh}, $mode) or $lock->{fatal}(N("aborting")); } else { - 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})); - } + warn_about_locker($lock); } } $lock->{locked} = 1; |