[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 06669cf85c46240901db86e22297b0814e76437e
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
+}

Comments

Ross Burton Dec. 14, 2018, 9:45 p.m.
On Fri, 30 Nov 2018 at 02:18, Chen Qi <Qi.Chen@windriver.com> wrote:
> 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.

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
Jacob Kroon Dec. 26, 2018, 4:06 p.m.
On Fri, Nov 30, 2018 at 3:18 AM Chen Qi <Qi.Chen@windriver.com> wrote:
>
> 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(+)
>
> 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

Shouldn't that be "127.0.0.1" ?

> +               fi
> +       fi
> +}
> --
> 1.9.1
>
> --
> _______________________________________________
> Openembedded-core mailing list
> Openembedded-core@lists.openembedded.org
> http://lists.openembedded.org/mailman/listinfo/openembedded-core
Jacob Kroon Dec. 26, 2018, 5:12 p.m.
On Wed, Dec 26, 2018 at 5:06 PM Jacob Kroon <jacob.kroon@gmail.com> wrote:
>
> On Fri, Nov 30, 2018 at 3:18 AM Chen Qi <Qi.Chen@windriver.com> wrote:
> >
> > 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(+)
> >
> > 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
>
> Shouldn'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.

> > +               fi
> > +       fi
> > +}
> > --
> > 1.9.1
> >
> > --
> > _______________________________________________
> > Openembedded-core mailing list
> > Openembedded-core@lists.openembedded.org
> > http://lists.openembedded.org/mailman/listinfo/openembedded-core
Richard Purdie Jan. 7, 2019, 2:38 p.m.
On Fri, 2018-12-14 at 21:45 +0000, Burton, Ross wrote:
> On Fri, 30 Nov 2018 at 02:18, Chen Qi <Qi.Chen@windriver.com> wrote:
> > 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.
> 
> 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.

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
Qi.Chen@windriver.com Jan. 8, 2019, 1:57 a.m.
On 01/07/2019 10:38 PM, Richard Purdie wrote:
> On Fri, 2018-12-14 at 21:45 +0000, Burton, Ross wrote:
>> On Fri, 30 Nov 2018 at 02:18, Chen Qi <Qi.Chen@windriver.com> wrote:
>>> 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.
>> 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.
> 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
>
>
Yes. I'll send out a new patch.

Best Regards,

Chen Qi