netbase: add entry to /etc/hosts according to /etc/hostname
cover netbase: add entry to /etc/hosts according to /etc/hostname
Changes in V2:
* use ${sysconfdir} instead of /etc
* check the existence of entry before adding it
The following changes since commit 41d89552620bfbc94031d314e6b3d0324f7a330e:
bitbake: fetch2: Avoid warning about incorrect character escaping in regex (2018-11-27 22:15:34 +0000)
are available in the git repository at:
git://git.pokylinux.org/poky-contrib ChenQi/netbase-hosts
http://git.pokylinux.org/cgit.cgi/poky-contrib/log/?h=ChenQi/netbase-hosts
Chen Qi (1):
netbase: add entry to /etc/hosts according to /etc/hostname
meta/recipes-core/netbase/netbase_5.4.bb | 11 +++++++++++ 1 file changed, 11 insertions(+)
Signature · 1 line
1.9.1
PATCH 1/1 netbase: add entry to /etc/hosts according to /etc/hostname
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.
--- meta/recipes-core/netbase/netbase_5.4.bb | 11 +++++++++++ 1 file changed, 11 insertions(+)
meta/recipes-core/netbase/netbase_5.4.bb +11 -0
@@ -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 +}
Signature · 1 line
1.9.1
Quoted 7 lines · Chen Qi
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/hostsaccording to/etc/hostname. We do this viapkg_postinstbecause hostname is set in base-files recipe.
RP and myself are still arguing over this so I thought I'd make my argument on the list for debate.
Updating /etc/hosts is being done with a postinst in netbase simply because /etc/hostname is contained in the base-files recipe. I advocate just moving the creation of /etc/hosts to base-files along with /etc/hostname, then base-files can write both files at the same time. There's already a dependency on base-files from netbase so there will be no change in the rootfs, a file will just move between packages.
Ross
Quoted 20 lines · Chen Qi
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/hostsaccording to/etc/hostname. We do this viapkg_postinstbecause hostname is set in base-files recipe.Signed-off-by Chen Qi <[email protected]>--- meta/recipes-core/netbase/netbase_5.4.bb | 11 +++++++++++ 1 file changed, 11 insertions(+)meta/recipes-core/netbase/netbase_5.4.bb +0
-0@@ -23,3 +23,14 @@ do_install () { }
meta/recipes-core/netbase/netbase_5.4.bb do_install () { · line 33
Quoted 10 lines
meta/recipes-core/netbase/netbase_5.4.bb +8
-0CONFFILES_${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
Shouldn't that be "127.0.0.1" ?
Quoted 11 lines
meta/recipes-core/netbase/netbase_5.4.bb +3
-1+ fi + fi +} --1.9.1
--
_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-core
Quoted 23 lines · Jacob Kroon
Quoted 21 lines · Chen Qi
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/hostsaccording to/etc/hostname. We do this viapkg_postinstbecause hostname is set in base-files recipe.Signed-off-by Chen Qi <[email protected]>--- meta/recipes-core/netbase/netbase_5.4.bb | 11 +++++++++++ 1 file changed, 11 insertions(+)meta/recipes-core/netbase/netbase_5.4.bb +0
-0@@ -23,3 +23,14 @@ do_install () { }
Quoted 12 lines
meta/recipes-core/netbase/netbase_5.4.bb do_install () { · line 33
Quoted 9 lines
meta/recipes-core/netbase/netbase_5.4.bb +8
-0CONFFILES_${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}/hostsShouldn't that be "127.0.0.1" ?
I thought it was a typo, but apparently there are reasons for using 127.0.1.1:
https://serverfault.com/questions/363095/why-does-my-hostname-appear-with-the-address-127-0-1-1-rather-than-127-0-0-1-in
Sorry for the noise.
Quoted 11 lines
Quoted 11 lines
meta/recipes-core/netbase/netbase_5.4.bb +3
-1+ fi + fi +} --1.9.1
--
_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-core
Quoted 12 lines · Ross
Quoted 7 lines · Chen Qi
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/hostsaccording to/etc/hostname. We do this viapkg_postinstbecause hostname is set in base-files recipe.RP and myself are still arguing over this so I thought I'd make my argument on the list for debate.
Quoted 7 lines
Updating
/etc/hostsis being done with a postinst in netbase simply because/etc/hostnameis contained in the base-files recipe. I advocate just moving the creation of/etc/hoststo base-files along with/etc/hostname, then base-files can write both files at the same time. There's already a dependency on base-files from netbase so there will be no change in the rootfs, a file will just move between packages.
Coming back to this after the holidays, I agree with Ross, we should move /etc/hostname to base-files and keep this simple. I'd like to get this fixed, could you update the patch please?
Cheers,
Richard
Quoted 19 lines · Richard Purdie
Quoted 11 lines · Ross
Quoted 7 lines · Chen Qi
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/hostsaccording to/etc/hostname. We do this viapkg_postinstbecause hostname is set in base-files recipe.RP and myself are still arguing over this so I thought I'd make my argument on the list for debate.
Quoted 7 lines
Updating
/etc/hostsis being done with a postinst in netbase simply because/etc/hostnameis contained in the base-files recipe. I advocate just moving the creation of/etc/hoststo base-files along with/etc/hostname, then base-files can write both files at the same time. There's already a dependency on base-files from netbase so there will be no change in the rootfs, a file will just move between packages.
Quoted 9 lines
Coming back to this after the holidays, I agree with Ross, we should move
/etc/hostnameto base-files and keep this simple. I'd like to get this fixed, could you update the patch please?Cheers,
Richard
Yes. I'll send out a new patch.
Best Regards,
Chen Qi