Merge pull request #4276 from ThomasWaldmann/fix-short-hostname

make "hostname" short, even on misconfigured systems, fixes #4262
This commit is contained in:
TW 2019-02-01 11:10:03 +01:00 committed by GitHub
commit 266fb02b9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 0 deletions

View File

@ -249,6 +249,9 @@ def getfqdn(name=''):
# 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 = getfqdn(hostname) fqdn = getfqdn(hostname)
# some people put the fqdn into /etc/hostname (which is wrong, should be the short hostname)
# fix this (do the same as "hostname --short" cli command does internally):
hostname = hostname.split('.')[0]
# uuid.getnode() is problematic in some environments (e.g. OpenVZ, see #3968) where the virtual MAC address # uuid.getnode() is problematic in some environments (e.g. OpenVZ, see #3968) where the virtual MAC address
# is all-zero. uuid.getnode falls back to returning a random value in that case, which is not what we want. # is all-zero. uuid.getnode falls back to returning a random value in that case, which is not what we want.