[1/1] netbase: add entry to /etc/hosts according to /etc/hostname

Submitted by Qi.Chen@windriver.com on Nov. 29, 2018, 9:37 a.m. | Patch ID: 156730

Details

Message ID 75835e51f6c88a58056350759080d5c0004562b7.1543484174.git.Qi.Chen@windriver.com
State Master Next
Commit a08bc7f28d31929efb8d86b1ca7f486cd0f1e737
Headers show

Commit Message

Qi.Chen@windriver.com Nov. 29, 2018, 9:37 a.m.
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>
---
 meta/recipes-core/netbase/netbase_5.4.bb | 11 +++++++++++
 1 file changed, 11 insertions(+)

Patch hide | download patch | download mbox

diff --git a/meta/recipes-core/netbase/netbase_5.4.bb b/meta/recipes-core/netbase/netbase_5.4.bb
index 5ab0c58..da9255a 100644
--- a/meta/recipes-core/netbase/netbase_5.4.bb
+++ b/meta/recipes-core/netbase/netbase_5.4.bb
@@ -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
+}