Patchwork [3,of,4,STABLE,V3] debuglocks: inform about lock corruption if readlink() returns empty string

login
register
mail settings
Submitter Katsunori FUJIWARA
Date May 1, 2017, 11:02 a.m.
Message ID <31c2495e338099e13252.1493636571@juju>
Download mbox | patch
Permalink /patch/20324/
State Accepted
Headers show

Comments

Katsunori FUJIWARA - May 1, 2017, 11:02 a.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1493636354 -32400
#      Mon May 01 19:59:14 2017 +0900
# Branch stable
# Node ID 31c2495e338099e1325289d2284b7a1eba98ba17
# Parent  cc349553a2126c8e28bc24402bab3bad7981c8c0
debuglocks: inform about lock corruption if readlink() returns empty string

Before this patch, if corrupted lock file makes vfs.readlink() return
empty string, "hg debuglocks" shows just empty string as "locker".

This patch makes debuglocks inform about lock corruption, if
readlink() returns empty string.

Newly added test is executed only on no-symlink platform, because it
isn't portable to create empty symlink.

  - man page of symlink() on Linux explicitly describes that it causes
    ENOENT at creation of empty symlink

  - POSIX specification for symlink() doesn't describe about empty
    symlink explicitly

    http://pubs.opengroup.org/onlinepubs/9699919799/functions/symlink.html

    AFAIK, (Open)Solaris can, but MacOS X can't.

Patch

diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -1192,6 +1192,8 @@  def debuglocks(ui, repo, **opts):
                     else:
                         locker = 'user %s, process %s, host %s' \
                                  % (user, pid, host)
+                elif not locker.strip():
+                    locker = 'user %s, but lock might be corrupted' % (user)
                 ui.write(("%-6s %s (%ds)\n") % (name + ":", locker, age))
                 return 1
             except OSError as e:
diff --git a/tests/test-no-symlinks.t b/tests/test-no-symlinks.t
--- a/tests/test-no-symlinks.t
+++ b/tests/test-no-symlinks.t
@@ -57,3 +57,18 @@  Bundle and extract again
   a
   $ cat b2.lnk && echo
   d/b
+
+Test handling lock corruption
+
+  $ hg debuglocks
+  lock:  free
+  wlock: free
+
+(emulate lock corruption by empty file)
+
+  $ printf '' > .hg/wlock
+
+  $ hg debuglocks
+  lock:  free
+  wlock: user *, but lock might be corrupted (*s) (glob)
+  [1]