mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-26 01:37:20 +00:00
use patched version of socket.getfqdn(), fixes #3471
This commit is contained in:
parent
5e4df7782b
commit
9b0d0f3127
1 changed files with 22 additions and 1 deletions
|
@ -185,10 +185,31 @@ def swidth(s):
|
||||||
return len(s)
|
return len(s)
|
||||||
|
|
||||||
|
|
||||||
|
# patched socket.getfqdn() - see https://bugs.python.org/issue5004
|
||||||
|
def getfqdn(name=''):
|
||||||
|
"""Get fully qualified domain name from name.
|
||||||
|
|
||||||
|
An empty argument is interpreted as meaning the local host.
|
||||||
|
"""
|
||||||
|
name = name.strip()
|
||||||
|
if not name or name == '0.0.0.0':
|
||||||
|
name = socket.gethostname()
|
||||||
|
try:
|
||||||
|
addrs = socket.getaddrinfo(name, None, 0, socket.SOCK_DGRAM, 0, socket.AI_CANONNAME)
|
||||||
|
except socket.error:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
for addr in addrs:
|
||||||
|
if addr[3]:
|
||||||
|
name = addr[3]
|
||||||
|
break
|
||||||
|
return name
|
||||||
|
|
||||||
|
|
||||||
# for performance reasons, only determine hostname / fqdn / hostid once.
|
# for performance reasons, only determine hostname / fqdn / hostid once.
|
||||||
# XXX this sometimes requires live internet access for issuing a DNS query in the background.
|
# XXX this sometimes requires live internet access for issuing a DNS query in the background.
|
||||||
hostname = socket.gethostname()
|
hostname = socket.gethostname()
|
||||||
fqdn = socket.getfqdn()
|
fqdn = getfqdn(hostname)
|
||||||
hostid = '%s@%s' % (fqdn, uuid.getnode())
|
hostid = '%s@%s' % (fqdn, uuid.getnode())
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue