Mercurial > hg
comparison mercurial/lock.py @ 31375:d57aa655ce97
lock: encode result of gethostname into a bytestring
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 12 Mar 2017 03:28:50 -0400 |
parents | e6a2b625e0d9 |
children | 2e48c776a874 |
comparison
equal
deleted
inserted
replaced
31374:d30fb3de4b40 | 31375:d57aa655ce97 |
---|---|
13 import socket | 13 import socket |
14 import time | 14 import time |
15 import warnings | 15 import warnings |
16 | 16 |
17 from . import ( | 17 from . import ( |
18 encoding, | |
18 error, | 19 error, |
19 pycompat, | 20 pycompat, |
20 util, | 21 util, |
21 ) | 22 ) |
22 | 23 |
25 | 26 |
26 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 |
27 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 |
28 extra Linux-specific pid namespace identifier. | 29 extra Linux-specific pid namespace identifier. |
29 """ | 30 """ |
30 result = socket.gethostname() | 31 result = socket.gethostname().encode( |
32 pycompat.sysstr(encoding.encoding), 'replace') | |
31 if pycompat.sysplatform.startswith('linux'): | 33 if pycompat.sysplatform.startswith('linux'): |
32 try: | 34 try: |
33 result += '/%x' % os.stat('/proc/self/ns/pid').st_ino | 35 result += '/%x' % os.stat('/proc/self/ns/pid').st_ino |
34 except OSError as ex: | 36 except OSError as ex: |
35 if ex.errno not in (errno.ENOENT, errno.EACCES, errno.ENOTDIR): | 37 if ex.errno not in (errno.ENOENT, errno.EACCES, errno.ENOTDIR): |