Merge pull request #3486 from ThomasWaldmann/fix-getfqdn-1.1

fix getfqdn (1.1)
This commit is contained in:
TW 2017-12-28 23:45:25 +01:00 committed by GitHub
commit 5ab238df2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 47 additions and 32 deletions

View file

@ -139,7 +139,7 @@ def check_extension_modules():
raise ExtensionModuleError
if borg.crypto.low_level.API_VERSION != '1.1_02':
raise ExtensionModuleError
if platform.API_VERSION != platform.OS_API_VERSION != '1.1_02':
if platform.API_VERSION != platform.OS_API_VERSION != '1.1_03':
raise ExtensionModuleError
if item.API_VERSION != '1.1_02':
raise ExtensionModuleError
@ -664,8 +664,8 @@ def format_line(format, data):
def replace_placeholders(text):
"""Replace placeholders in text with their values."""
from .platform import fqdn
current_time = datetime.now()
fqdn = socket.getfqdn()
data = {
'pid': os.getpid(),
'fqdn': fqdn,

View file

@ -10,12 +10,12 @@ from .base import acl_get, acl_set
from .base import set_flags, get_flags
from .base import SaveFile, SyncFile, sync_dir, fdatasync, safe_fadvise
from .base import swidth, API_VERSION
from .base import process_alive, get_process_id, local_pid_alive
from .base import process_alive, get_process_id, local_pid_alive, fqdn, hostname, hostid
OS_API_VERSION = API_VERSION
if not sys.platform.startswith(('win32', )):
from .posix import process_alive, get_process_id, local_pid_alive
from .posix import process_alive, local_pid_alive
if sys.platform.startswith('linux'): # pragma: linux only
from .linux import API_VERSION as OS_API_VERSION

View file

@ -1,5 +1,7 @@
import errno
import os
import socket
import uuid
from borg.helpers import truncate_and_unlink
@ -15,7 +17,7 @@ platform API: that way platform APIs provided by the platform-specific support m
are correctly composed into the base functionality.
"""
API_VERSION = '1.1_02'
API_VERSION = '1.1_03'
fdatasync = getattr(os, 'fdatasync', os.fsync)
@ -183,12 +185,44 @@ def swidth(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.
# XXX this sometimes requires live internet access for issuing a DNS query in the background.
hostname = socket.gethostname()
fqdn = getfqdn(hostname)
hostid = '%s@%s' % (fqdn, uuid.getnode())
def get_process_id():
"""
Return identification tuple (hostname, pid, thread_id) for 'us'. If this is a FUSE process, then the PID will be
that of the parent, not the forked FUSE child.
Return identification tuple (hostname, pid, thread_id) for 'us'.
This always returns the current pid, which might be different from before, e.g. if daemonize() was used.
Note: Currently thread_id is *always* zero.
"""
raise NotImplementedError
thread_id = 0
pid = os.getpid()
return hostid, pid, thread_id
def process_alive(host, pid, thread):

View file

@ -4,7 +4,7 @@ from ..helpers import user2uid, group2gid
from ..helpers import safe_decode, safe_encode
from .posix import swidth
API_VERSION = '1.1_02'
API_VERSION = '1.1_03'
cdef extern from "sys/acl.h":
ctypedef struct _acl_t:

View file

@ -4,7 +4,7 @@ from ..helpers import posix_acl_use_stored_uid_gid
from ..helpers import safe_encode, safe_decode
from .posix import swidth
API_VERSION = '1.1_02'
API_VERSION = '1.1_03'
cdef extern from "errno.h":
int errno

View file

@ -13,7 +13,7 @@ from .posix import swidth
from libc cimport errno
from libc.stdint cimport int64_t
API_VERSION = '1.1_02'
API_VERSION = '1.1_03'
cdef extern from "sys/types.h":
int ACL_TYPE_ACCESS

View file

@ -1,8 +1,5 @@
import errno
import os
import uuid
import socket
import subprocess
cdef extern from "wchar.h":
@ -18,23 +15,6 @@ def swidth(s):
return str_len
# for performance reasons, only determine the hostname once.
# XXX this sometimes requires live internet access for issuing a DNS query in the background.
_hostname = '%s@%s' % (socket.getfqdn(), uuid.getnode())
def get_process_id():
"""
Return identification tuple (hostname, pid, thread_id) for 'us'.
This always returns the current pid, which might be different from before, e.g. if daemonize() was used.
Note: Currently thread_id is *always* zero.
"""
thread_id = 0
pid = os.getpid()
return _hostname, pid, thread_id
def process_alive(host, pid, thread):
"""
Check if the (host, pid, thread_id) combination corresponds to a potentially alive process.
@ -43,8 +23,9 @@ def process_alive(host, pid, thread):
returns always True, since there is no real way to check.
"""
from . import local_pid_alive
from . import hostid
if host != _hostname:
if host != hostid:
return True
if thread != 0: