From 8b0806e8df366f0b0b29c74b4856bbfcda632ed6 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Sun, 23 Jun 2019 01:04:22 +0200 Subject: libdpkg: Clarify lock contender error message Print the PID of the lock contender, switch the tense to past as the lock might not be locked anymore by the time we finish, and add a warning explaining that removing the lock file is never the correct solution. --- debian/changelog | 3 +++ lib/dpkg/file.c | 19 ++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/debian/changelog b/debian/changelog index 206c0e6cf..ff6e3cdb5 100644 --- a/debian/changelog +++ b/debian/changelog @@ -16,6 +16,9 @@ dpkg (1.20.0) UNRELEASED; urgency=medium to specify multiple packages. Closes: #926669 Based on a patch by Frank Schaefer . * perl: Remove support for versioned GnuPG 2 program and packages. + * libdpkg: Clarify lock contender error message. Print the PID of the lock + contender, and add a warning explaining that removing the lock file is + never the correct solution. * Perl modules: - Dpkg::Source::Package: Verify original tarball signatures at build time. * Documentation: diff --git a/lib/dpkg/file.c b/lib/dpkg/file.c index 614d969e3..ceda51047 100644 --- a/lib/dpkg/file.c +++ b/lib/dpkg/file.c @@ -189,10 +189,23 @@ file_lock(int *lockfd, enum file_lock_flags flags, const char *filename, lock_cmd = F_SETLK; if (fcntl(*lockfd, lock_cmd, &fl) == -1) { - if (errno == EACCES || errno == EAGAIN) - ohshit(_("%s is locked by another process"), desc); - else + const char *warnmsg; + + if (errno != EACCES && errno != EAGAIN) ohshite(_("unable to lock %s"), desc); + + warnmsg = _("Note: removing the lock file is always wrong, " + "and can end up damaging the\n" + "locked area and the entire system. " + "See ."); + + file_lock_setup(&fl, F_WRLCK); + if (fcntl(*lockfd, F_GETLK, &fl) == -1) + ohshit(_("%s was locked by another process\n%s"), + desc, warnmsg); + + ohshit(_("%s was locked by another process with pid %d\n%s"), + desc, fl.l_pid, warnmsg); } push_cleanup(file_unlock_cleanup, ~0, 3, lockfd, filename, desc); -- cgit v1.2.3