From 94ead5c886348823bab7f1c33abdb4bad368d7b2 Mon Sep 17 00:00:00 2001 From: Thierry Vignaud Date: Fri, 6 Jan 2012 19:43:50 +0000 Subject: (warn_about_locker) split it out of _lock() --- urpm/lock.pm | 22 +++++++++++++--------- 1 file 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; -- cgit v1.2.1