[OE-core] [PATCH 1/1] netbase: add entry to /etc/hosts according to /etc/hostname

Burton, Ross ross.burton at intel.com
Wed Nov 28 10:26:00 UTC 2018


What if the hostname entry already exists? $sysconfdir instead of
hard-coding etc.

I can't help but think a better solution would be to simply move
/etc/hosts to base-files, so it can be updated at the same time as
hostname.

Ross
On Mon, 26 Nov 2018 at 06:51, Chen Qi <Qi.Chen at 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 at windriver.com>
> ---
>  meta/recipes-core/netbase/netbase_5.4.bb | 9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/meta/recipes-core/netbase/netbase_5.4.bb b/meta/recipes-core/netbase/netbase_5.4.bb
> index 5ab0c58..384c430 100644
> --- a/meta/recipes-core/netbase/netbase_5.4.bb
> +++ b/meta/recipes-core/netbase/netbase_5.4.bb
> @@ -23,3 +23,12 @@ do_install () {
>  }
>
>  CONFFILES_${PN} = "${sysconfdir}/hosts"
> +
> +RDEPENDS_${PN} += "base-files"
> +
> +pkg_postinst_${PN} () {
> +       if [ -s $D/etc/hostname ]; then
> +               hostname=`cat $D/etc/hostname`
> +               echo "127.0.1.1 $hostname" >> $D/etc/hosts
> +       fi
> +}
> --
> 1.9.1
>
> --
> _______________________________________________
> Openembedded-core mailing list
> Openembedded-core at lists.openembedded.org
> http://lists.openembedded.org/mailman/listinfo/openembedded-core


More information about the Openembedded-core mailing list