[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[dak/master 6/6] daklib/utils.py: use socket.getfqdn() to determine the hostname



To: debian-dak@lists.debian.org
Cc: Philipp Kern <pkern@debian.org>
Date: Tue, 23 Feb 2010 11:35:20 +0100
Resent-From: debian-dak@lists.debian.org

The current socket.gethostbyaddr(socket.gethostname()) fails horribly on
our IPv6 enabled machine.  What we really want is the FQDN of the host so
let's use socket's getfqdn().  Of course that needs proper setup of the
hostname in the system, but I think we can rely on that working.

Signed-off-by: Philipp Kern <pkern@debian.org>
---
 daklib/utils.py |   24 ++++++++++++------------
 1 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/daklib/utils.py b/daklib/utils.py
index b1a34c9..0896d57 100755
--- a/daklib/utils.py
+++ b/daklib/utils.py
@@ -730,20 +730,20 @@ def copy (src, dest, overwrite = 0, perms = 0664):
 ################################################################################
 
 def where_am_i ():
-    res = socket.gethostbyaddr(socket.gethostname())
-    database_hostname = Cnf.get("Config::" + res[0] + "::DatabaseHostname")
+    res = socket.getfqdn()
+    database_hostname = Cnf.get("Config::" + res + "::DatabaseHostname")
     if database_hostname:
         return database_hostname
     else:
-        return res[0]
+        return res
 
 def which_conf_file ():
     if os.getenv('DAK_CONFIG'):
         return os.getenv('DAK_CONFIG')
 
-    res = socket.gethostbyaddr(socket.gethostname())
+    res = socket.getfqdn()
     # In case we allow local config files per user, try if one exists
-    if Cnf.FindB("Config::" + res[0] + "::AllowLocalConfig"):
+    if Cnf.FindB("Config::" + res + "::AllowLocalConfig"):
         homedir = os.getenv("HOME")
         confpath = os.path.join(homedir, "/etc/dak.conf")
         if os.path.exists(confpath):
@@ -751,27 +751,27 @@ def which_conf_file ():
 
     # We are still in here, so there is no local config file or we do
     # not allow local files. Do the normal stuff.
-    if Cnf.get("Config::" + res[0] + "::DakConfig"):
-        return Cnf["Config::" + res[0] + "::DakConfig"]
+    if Cnf.get("Config::" + res + "::DakConfig"):
+        return Cnf["Config::" + res + "::DakConfig"]
 
     return default_config
 
 def which_apt_conf_file ():
-    res = socket.gethostbyaddr(socket.gethostname())
+    res = socket.getfqdn()
     # In case we allow local config files per user, try if one exists
-    if Cnf.FindB("Config::" + res[0] + "::AllowLocalConfig"):
+    if Cnf.FindB("Config::" + res + "::AllowLocalConfig"):
         homedir = os.getenv("HOME")
         confpath = os.path.join(homedir, "/etc/dak.conf")
         if os.path.exists(confpath):
             apt_pkg.ReadConfigFileISC(Cnf,default_config)
 
-    if Cnf.get("Config::" + res[0] + "::AptConfig"):
-        return Cnf["Config::" + res[0] + "::AptConfig"]
+    if Cnf.get("Config::" + res + "::AptConfig"):
+        return Cnf["Config::" + res + "::AptConfig"]
     else:
         return default_apt_config
 
 def which_alias_file():
-    hostname = socket.gethostbyaddr(socket.gethostname())[0]
+    hostname = socket.getfqdn()
     aliasfn = '/var/lib/misc/'+hostname+'/forward-alias'
     if os.path.exists(aliasfn):
         return aliasfn
-- 
1.6.5


Reply to: