Mercurial > public > mercurial-scm > hg
comparison mercurial/lock.py @ 31378:2e48c776a874
lock: do not encode result of gethostname on Python 2
If a hostname contained non-ascii character, str.encode() would first try
to decode it to a unicode and raise UnicodeDecodeError.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 12 Mar 2017 16:26:34 -0700 |
parents | d57aa655ce97 |
children | e1938d6051da |
comparison
equal
deleted
inserted
replaced
31377:52ee1b5ac277 | 31378:2e48c776a874 |
---|---|
26 | 26 |
27 It's useful to detect "dead" processes and remove stale locks with | 27 It's useful to detect "dead" processes and remove stale locks with |
28 confidence. Typically it's just hostname. On modern linux, we include an | 28 confidence. Typically it's just hostname. On modern linux, we include an |
29 extra Linux-specific pid namespace identifier. | 29 extra Linux-specific pid namespace identifier. |
30 """ | 30 """ |
31 result = socket.gethostname().encode( | 31 result = socket.gethostname() |
32 pycompat.sysstr(encoding.encoding), 'replace') | 32 if pycompat.ispy3: |
33 result = result.encode(pycompat.sysstr(encoding.encoding), 'replace') | |
33 if pycompat.sysplatform.startswith('linux'): | 34 if pycompat.sysplatform.startswith('linux'): |
34 try: | 35 try: |
35 result += '/%x' % os.stat('/proc/self/ns/pid').st_ino | 36 result += '/%x' % os.stat('/proc/self/ns/pid').st_ino |
36 except OSError as ex: | 37 except OSError as ex: |
37 if ex.errno not in (errno.ENOENT, errno.EACCES, errno.ENOTDIR): | 38 if ex.errno not in (errno.ENOENT, errno.EACCES, errno.ENOTDIR): |