This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch master
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=8b0806e8df366f0b0b29c74b4856bbfcda632ed6

commit 8b0806e8df366f0b0b29c74b4856bbfcda632ed6
Author: Guillem Jover <[email protected]>
AuthorDate: Sun Jun 23 01:04:22 2019 +0200

    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 <[email protected]>.
   * 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 <https://wiki.debian.org/Teams/Dpkg/FAQ>.");
+
+               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);

-- 
Dpkg.Org's dpkg

Reply via email to