]> code.ossystems Code Review - openembedded-core.git/commitdiff
netbase: add entry to /etc/hosts according to /etc/hostname
authorChen Qi <Qi.Chen@windriver.com>
Fri, 30 Nov 2018 02:24:41 +0000 (10:24 +0800)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 3 Jan 2019 12:36:02 +0000 (12:36 +0000)
We default hostname to ${MACHINE}, but it's not in /etc/hosts,
resulting in commands like `hostname -f' failing due to lack
of entry.

So add entry to /etc/hosts according to /etc/hostname. We do
this via pkg_postinst because hostname is set in base-files
recipe.

Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/recipes-core/netbase/netbase_5.4.bb

index 5ab0c58f8369457f445e9225f30681926d313272..da9255a2bf6a45d1c7886f0f338f5dcfeb740e31 100644 (file)
@@ -23,3 +23,14 @@ do_install () {
 }
 
 CONFFILES_${PN} = "${sysconfdir}/hosts"
+
+RDEPENDS_${PN} += "base-files"
+
+pkg_postinst_${PN} () {
+       if [ -s $D${sysconfdir}/hostname ]; then
+               hostname=`cat $D${sysconfdir}/hostname`
+               if ! grep -q "[[:space:]]$hostname[[:space:]]*" $D${sysconfdir}/hosts; then
+                       echo "127.0.1.1 $hostname" >> $D${sysconfdir}/hosts
+               fi
+       fi
+}