[elbe-devel] [PATCH] fix /etc/hosts generation

Manuel Traut manut at linutronix.de
Fri Nov 30 10:13:18 CET 2018


fix github issue #185:

--8<--
The format of the /etc/hosts file for Debian Stretch is described here:
https://manpages.debian.org/stretch/manpages/hosts.5.en.html. According to this
document, the hostname
should be specified using 127.0.1.1 and not 127.0.01. There should be a tab
instead of a space between
127.0.1.1 and the hostname.

When giving an empty **<domain></domain>** section, the **/etc/hosts** file will
contain test.None. In
most cases we don't need/want a domain entry. There seems to be no way to tell
Elbe to skip generating a
domain entry.
--8<--

The statement about tabs as delimiters is wrong:
"Fields  of  the  entry are separated by any number of blanks and/or tab characters."

Signed-off-by: Manuel Traut <manut at linutronix.de>
---
 elbepack/rfs.py   | 12 +++++++-----
 schema/dbsfed.xsd |  2 +-
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/elbepack/rfs.py b/elbepack/rfs.py
index 4009f61b..eec4e6a0 100644
--- a/elbepack/rfs.py
+++ b/elbepack/rfs.py
@@ -283,12 +283,14 @@ class BuildEnv (object):
             (passwd, passwd))
 
         hostname = self.xml.text("target/hostname")
-        domain = self.xml.text("target/domain")
+        fqdn = hostname
+        if self.xml.has("target/domain"):
+            fqdn = ("%s.%s" % (hostname, self.xml.text("target/domain")))
 
         self.log.chroot(
             self.rfs.path,
-            """/bin/sh -c 'echo "127.0.0.1 %s.%s %s elbe-daemon" >> """
-            """/etc/hosts'""" % (hostname, domain, hostname))
+            """/bin/sh -c 'echo "127.0.1.1 %s %s elbe-daemon" >> """
+            """/etc/hosts'""" % (fqdn,hostname))
 
         self.log.chroot(
             self.rfs.path,
@@ -296,8 +298,8 @@ class BuildEnv (object):
 
         self.log.chroot(
             self.rfs.path,
-            """/bin/sh -c 'echo "%s.%s" > """
-            """/etc/mailname'""" % (hostname, domain))
+            """/bin/sh -c 'echo "%s" > """
+            """/etc/mailname'""" % (fqdn))
 
         if self.xml.has("target/console"):
             serial_con, serial_baud = self.xml.text(
diff --git a/schema/dbsfed.xsd b/schema/dbsfed.xsd
index d52b80f6..76674c62 100644
--- a/schema/dbsfed.xsd
+++ b/schema/dbsfed.xsd
@@ -744,7 +744,7 @@
           </documentation>
         </annotation>
       </element>
-      <element name="domain" type="rfs:string" minOccurs="1" maxOccurs="1">
+      <element name="domain" type="rfs:string" minOccurs="0" maxOccurs="1">
         <annotation>
           <documentation>
             domainname of the network the target system is part of
-- 
2.19.1




More information about the elbe-devel mailing list