Patchwork image.bbclass: Adding loop back for machine name in hosts file

login
register
mail settings
Submitter Sujith H
Date Aug. 4, 2014, 1:57 p.m.
Message ID <1407160628-30775-1-git-send-email-sujith.h@gmail.com>
Download mbox | patch
Permalink /patch/77197/
State New
Headers show

Comments

Sujith H - Aug. 4, 2014, 1:57 p.m.
From: Sujith H <Sujith_Haridasan@mentor.com>

If hostname is not added to /etc/hosts file then rpcinfo
command fails when hostname is passed as argument. This was
observed when rpcinfo command was tested on freescale target.
Below was the output observed without this change.

root@mx6q:~# rpcinfo -s mx6q
rpcinfo: can't contact rpcbind: RPC: (unknown error code)

Below is the output after this change:
root@mx6q:~# rpcinfo -s mx6q
   program version(s) netid(s)                         service     owner
    100000  2,3,4     local,udp,tcp,udp6,tcp6          portmapper  superuser
root@mx6q:~#

Signed-off-by: Sujith H <Sujith_Haridasan@mentor.com>
---
 meta/classes/image.bbclass | 8 ++++++++
 1 file changed, 8 insertions(+)
Sujith H - Aug. 4, 2014, 2:02 p.m.
Hi,

Let me know if any more changes have to be made to make this patch look
better.



On Mon, Aug 4, 2014 at 7:27 PM, Sujith H <sujith.h@gmail.com> wrote:

> From: Sujith H <Sujith_Haridasan@mentor.com>
>
> If hostname is not added to /etc/hosts file then rpcinfo
> command fails when hostname is passed as argument. This was
> observed when rpcinfo command was tested on freescale target.
> Below was the output observed without this change.
>
> root@mx6q:~# rpcinfo -s mx6q
> rpcinfo: can't contact rpcbind: RPC: (unknown error code)
>
> Below is the output after this change:
> root@mx6q:~# rpcinfo -s mx6q
>    program version(s) netid(s)                         service     owner
>     100000  2,3,4     local,udp,tcp,udp6,tcp6          portmapper
>  superuser
> root@mx6q:~#
>
> Signed-off-by: Sujith H <Sujith_Haridasan@mentor.com>
> ---
>  meta/classes/image.bbclass | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
> index 82605f2..7a5a5c1 100644
> --- a/meta/classes/image.bbclass
> +++ b/meta/classes/image.bbclass
> @@ -341,6 +341,14 @@ ssh_disable_dns_lookup () {
>         fi
>  }
>
> +ROOTFS_POSTPROCESS_COMMAND += "add_machine_name_loop_back;"
> +
> +add_machine_name_loop_back() {
> +    if [ -n ${MACHINE} ]; then
> +         echo 127.0.1.1 "       "${MACHINE} >>
> ${IMAGE_ROOTFS}${sysconfdir}/hosts
> +    fi
> +}
> +
>  # Enable postinst logging if debug-tweaks is enabled
>  postinst_enable_logging () {
>         mkdir -p ${IMAGE_ROOTFS}${sysconfdir}/default
> --
> 1.8.4
>
>
Thanks,
Sujith H
Paul Eggleton - Aug. 4, 2014, 2:18 p.m.
Hi Sujith,

On Monday 04 August 2014 19:27:08 Sujith H wrote:
> From: Sujith H <Sujith_Haridasan@mentor.com>
> 
> If hostname is not added to /etc/hosts file then rpcinfo
> command fails when hostname is passed as argument. This was
> observed when rpcinfo command was tested on freescale target.
> Below was the output observed without this change.
> 
> root@mx6q:~# rpcinfo -s mx6q
> rpcinfo: can't contact rpcbind: RPC: (unknown error code)
> 
> Below is the output after this change:
> root@mx6q:~# rpcinfo -s mx6q
>    program version(s) netid(s)                         service     owner
>     100000  2,3,4     local,udp,tcp,udp6,tcp6          portmapper  superuser
> root@mx6q:~#
> 
> Signed-off-by: Sujith H <Sujith_Haridasan@mentor.com>
> ---
>  meta/classes/image.bbclass | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
> index 82605f2..7a5a5c1 100644
> --- a/meta/classes/image.bbclass
> +++ b/meta/classes/image.bbclass
> @@ -341,6 +341,14 @@ ssh_disable_dns_lookup () {
>  	fi
>  }
> 
> +ROOTFS_POSTPROCESS_COMMAND += "add_machine_name_loop_back;"
> +
> +add_machine_name_loop_back() {
> +    if [ -n ${MACHINE} ]; then
> +         echo 127.0.1.1 "       "${MACHINE} >>
> ${IMAGE_ROOTFS}${sysconfdir}/hosts +    fi
> +}
> +

I think in the earlier discussion the conclusion was that we do not want this 
enabled by default, which the above will do.

The question I have is, if this isn't a good idea, is there a better solution?

Cheers,
Paul
Sujith H - Aug. 4, 2014, 2:33 p.m.
Hi Paul,


On Mon, Aug 4, 2014 at 7:48 PM, Paul Eggleton <paul.eggleton@linux.intel.com
> wrote:

> Hi Sujith,
>
> On Monday 04 August 2014 19:27:08 Sujith H wrote:
> > From: Sujith H <Sujith_Haridasan@mentor.com>
> >
> > If hostname is not added to /etc/hosts file then rpcinfo
> > command fails when hostname is passed as argument. This was
> > observed when rpcinfo command was tested on freescale target.
> > Below was the output observed without this change.
> >
> > root@mx6q:~# rpcinfo -s mx6q
> > rpcinfo: can't contact rpcbind: RPC: (unknown error code)
> >
> > Below is the output after this change:
> > root@mx6q:~# rpcinfo -s mx6q
> >    program version(s) netid(s)                         service     owner
> >     100000  2,3,4     local,udp,tcp,udp6,tcp6          portmapper
>  superuser
> > root@mx6q:~#
> >
> > Signed-off-by: Sujith H <Sujith_Haridasan@mentor.com>
> > ---
> >  meta/classes/image.bbclass | 8 ++++++++
> >  1 file changed, 8 insertions(+)
> >
> > diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
> > index 82605f2..7a5a5c1 100644
> > --- a/meta/classes/image.bbclass
> > +++ b/meta/classes/image.bbclass
> > @@ -341,6 +341,14 @@ ssh_disable_dns_lookup () {
> >       fi
> >  }
> >
> > +ROOTFS_POSTPROCESS_COMMAND += "add_machine_name_loop_back;"
> > +
> > +add_machine_name_loop_back() {
> > +    if [ -n ${MACHINE} ]; then
> > +         echo 127.0.1.1 "       "${MACHINE} >>
> > ${IMAGE_ROOTFS}${sysconfdir}/hosts +    fi
> > +}
> > +
>
> I think in the earlier discussion the conclusion was that we do not want
> this
> enabled by default, which the above will do.
>
> The question I have is, if this isn't a good idea, is there a better
> solution?
>
>
I totally agree with the discussion. Is it a good idea to implement like
check made for zap_empty_root_password?
For zap_empty_root_password there is a conditional check if debug-tweaks
are enabled then zap_empty_root_password is
called. So can I use debug-tweaks to handle add_machine_name_loop_back in
the patch?


Cheers,
> Paul
>
> --
>
> Paul Eggleton
> Intel Open Source Technology Centre
>

Thanks,

Sujith H
Paul Eggleton - Aug. 4, 2014, 2:49 p.m.
On Monday 04 August 2014 20:03:09 sujith h wrote:
> Hi Paul,
> 
> 
> On Mon, Aug 4, 2014 at 7:48 PM, Paul Eggleton <paul.eggleton@linux.intel.com
> > wrote:
> > 
> > Hi Sujith,
> > 
> > On Monday 04 August 2014 19:27:08 Sujith H wrote:
> > > From: Sujith H <Sujith_Haridasan@mentor.com>
> > > 
> > > If hostname is not added to /etc/hosts file then rpcinfo
> > > command fails when hostname is passed as argument. This was
> > > observed when rpcinfo command was tested on freescale target.
> > > Below was the output observed without this change.
> > > 
> > > root@mx6q:~# rpcinfo -s mx6q
> > > rpcinfo: can't contact rpcbind: RPC: (unknown error code)
> > > 
> > > Below is the output after this change:
> > > root@mx6q:~# rpcinfo -s mx6q
> > > 
> > >    program version(s) netid(s)                         service     owner
> > >    
> > >     100000  2,3,4     local,udp,tcp,udp6,tcp6          portmapper
> >  
> >  superuser
> >  
> > > root@mx6q:~#
> > > 
> > > Signed-off-by: Sujith H <Sujith_Haridasan@mentor.com>
> > > ---
> > > 
> > >  meta/classes/image.bbclass | 8 ++++++++
> > >  1 file changed, 8 insertions(+)
> > > 
> > > diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
> > > index 82605f2..7a5a5c1 100644
> > > --- a/meta/classes/image.bbclass
> > > +++ b/meta/classes/image.bbclass
> > > @@ -341,6 +341,14 @@ ssh_disable_dns_lookup () {
> > > 
> > >       fi
> > >  
> > >  }
> > > 
> > > +ROOTFS_POSTPROCESS_COMMAND += "add_machine_name_loop_back;"
> > > +
> > > +add_machine_name_loop_back() {
> > > +    if [ -n ${MACHINE} ]; then
> > > +         echo 127.0.1.1 "       "${MACHINE} >>
> > > ${IMAGE_ROOTFS}${sysconfdir}/hosts +    fi
> > > +}
> > > +
> > 
> > I think in the earlier discussion the conclusion was that we do not want
> > this
> > enabled by default, which the above will do.
> > 
> > The question I have is, if this isn't a good idea, is there a better
> > solution?
> 
> I totally agree with the discussion. Is it a good idea to implement like
> check made for zap_empty_root_password?
> For zap_empty_root_password there is a conditional check if debug-tweaks
> are enabled then zap_empty_root_password is
> called. So can I use debug-tweaks to handle add_machine_name_loop_back in
> the patch?

No, that would not be right - debug-tweaks is for a specific purpose which is 
unrelated to this.

Cheers,
Paul
Sujith H - Aug. 4, 2014, 3:29 p.m.
On Mon, Aug 4, 2014 at 8:19 PM, Paul Eggleton <paul.eggleton@linux.intel.com
> wrote:

> On Monday 04 August 2014 20:03:09 sujith h wrote:
> > Hi Paul,
> >
> >
> > On Mon, Aug 4, 2014 at 7:48 PM, Paul Eggleton <
> paul.eggleton@linux.intel.com
> > > wrote:
> > >
> > > Hi Sujith,
> > >
> > > On Monday 04 August 2014 19:27:08 Sujith H wrote:
> > > > From: Sujith H <Sujith_Haridasan@mentor.com>
> > > >
> > > > If hostname is not added to /etc/hosts file then rpcinfo
> > > > command fails when hostname is passed as argument. This was
> > > > observed when rpcinfo command was tested on freescale target.
> > > > Below was the output observed without this change.
> > > >
> > > > root@mx6q:~# rpcinfo -s mx6q
> > > > rpcinfo: can't contact rpcbind: RPC: (unknown error code)
> > > >
> > > > Below is the output after this change:
> > > > root@mx6q:~# rpcinfo -s mx6q
> > > >
> > > >    program version(s) netid(s)                         service
> owner
> > > >
> > > >     100000  2,3,4     local,udp,tcp,udp6,tcp6          portmapper
> > >
> > >  superuser
> > >
> > > > root@mx6q:~#
> > > >
> > > > Signed-off-by: Sujith H <Sujith_Haridasan@mentor.com>
> > > > ---
> > > >
> > > >  meta/classes/image.bbclass | 8 ++++++++
> > > >  1 file changed, 8 insertions(+)
> > > >
> > > > diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
> > > > index 82605f2..7a5a5c1 100644
> > > > --- a/meta/classes/image.bbclass
> > > > +++ b/meta/classes/image.bbclass
> > > > @@ -341,6 +341,14 @@ ssh_disable_dns_lookup () {
> > > >
> > > >       fi
> > > >
> > > >  }
> > > >
> > > > +ROOTFS_POSTPROCESS_COMMAND += "add_machine_name_loop_back;"
> > > > +
> > > > +add_machine_name_loop_back() {
> > > > +    if [ -n ${MACHINE} ]; then
> > > > +         echo 127.0.1.1 "       "${MACHINE} >>
> > > > ${IMAGE_ROOTFS}${sysconfdir}/hosts +    fi
> > > > +}
> > > > +
> > >
> > > I think in the earlier discussion the conclusion was that we do not
> want
> > > this
> > > enabled by default, which the above will do.
> > >
> > > The question I have is, if this isn't a good idea, is there a better
> > > solution?
> >
> > I totally agree with the discussion. Is it a good idea to implement like
> > check made for zap_empty_root_password?
> > For zap_empty_root_password there is a conditional check if debug-tweaks
> > are enabled then zap_empty_root_password is
> > called. So can I use debug-tweaks to handle add_machine_name_loop_back in
> > the patch?
>
> No, that would not be right - debug-tweaks is for a specific purpose which
> is
> unrelated to this.
>

Ok. How about adding :

ROOTFS_POSTPROCESS_COMMAND += '${@base_contains("TOOLCHAIN_TARGET_TASK",
"packagegroup-core-boot", "add_machine_name_loop_back; ", "",d)}'

Again here the problem is that when packagegroup-core-boot will be added,
this change will be forced to rootfs :(

>
> Cheers,
> Paul
>
> --
>
> Paul Eggleton
> Intel Open Source Technology Centre
>

Thanks,
Sujith H
Enrico Scholz - Aug. 4, 2014, 3:35 p.m.
Sujith H <sujith.h-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> If hostname is not added to /etc/hosts file then rpcinfo command fails
> when hostname is passed as argument.
> ...
> root@mx6q:~# rpcinfo -s mx6q
> rpcinfo: can't contact rpcbind: RPC: (unknown error code)

Is this really a common/valid use case?  'rpcinfo' is a debug tool and
when you want information about the local host, you can execute

# rpcinfo -s localhost

IMHO, when using network related functionality, you have to setup
networking.  This means:

- setup the hostname; using ${MACHINE} is ambiguous with more than one
  device and the string can contain chars forbidden by DNS ('_')

- setup name resolving; this can be done by ordinary DNS, (unambiguous)
  /etc/hosts, mDNS


When DNS mapping of ${MACHINE} (or better `hostname`) without working
DNS is really required, 'systemd' contains 'libnss_myhostname.so' (which
is to be registered in /etc/nsswitch) which returns '127.0.0.2' as a
fallback.


Enrico
Sujith H - Aug. 4, 2014, 3:50 p.m.
On Mon, Aug 4, 2014 at 9:05 PM, Enrico Scholz <
enrico.scholz@sigma-chemnitz.de> wrote:

> Sujith H <sujith.h-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
>
> > If hostname is not added to /etc/hosts file then rpcinfo command fails
> > when hostname is passed as argument.
> > ...
> > root@mx6q:~# rpcinfo -s mx6q
> > rpcinfo: can't contact rpcbind: RPC: (unknown error code)
>
> Is this really a common/valid use case?  'rpcinfo' is a debug tool and
> when you want information about the local host, you can execute
>
> # rpcinfo -s localhost
>
> IMHO, when using network related functionality, you have to setup
> networking.  This means:
>
> - setup the hostname; using ${MACHINE} is ambiguous with more than one
>   device and the string can contain chars forbidden by DNS ('_')
>
> - setup name resolving; this can be done by ordinary DNS, (unambiguous)
>   /etc/hosts, mDNS
>
>
> When DNS mapping of ${MACHINE} (or better `hostname`) without working
> DNS is really required, 'systemd' contains 'libnss_myhostname.so' (which
> is to be registered in /etc/nsswitch) which returns '127.0.0.2' as a
> fallback.
>
>
Is it ok to read from /etc/hostname and then have that in the /etc/hosts
file, rather than using ${MACHINE}?

>
> Enrico
> --
> _______________________________________________
> Openembedded-core mailing list
> Openembedded-core@lists.openembedded.org
> http://lists.openembedded.org/mailman/listinfo/openembedded-core
>
Khem Raj - Aug. 4, 2014, 10:18 p.m.
On 14-08-04 15:18:05, Paul Eggleton wrote:
> Hi Sujith,
> 
> On Monday 04 August 2014 19:27:08 Sujith H wrote:
> > From: Sujith H <Sujith_Haridasan@mentor.com>
> > 
> > If hostname is not added to /etc/hosts file then rpcinfo
> > command fails when hostname is passed as argument. This was
> > observed when rpcinfo command was tested on freescale target.
> > Below was the output observed without this change.
> > 
> > root@mx6q:~# rpcinfo -s mx6q
> > rpcinfo: can't contact rpcbind: RPC: (unknown error code)
> > 
> > Below is the output after this change:
> > root@mx6q:~# rpcinfo -s mx6q
> >    program version(s) netid(s)                         service     owner
> >     100000  2,3,4     local,udp,tcp,udp6,tcp6          portmapper  superuser
> > root@mx6q:~#
> > 
> > Signed-off-by: Sujith H <Sujith_Haridasan@mentor.com>
> > ---
> >  meta/classes/image.bbclass | 8 ++++++++
> >  1 file changed, 8 insertions(+)
> > 
> > diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
> > index 82605f2..7a5a5c1 100644
> > --- a/meta/classes/image.bbclass
> > +++ b/meta/classes/image.bbclass
> > @@ -341,6 +341,14 @@ ssh_disable_dns_lookup () {
> >  	fi
> >  }
> > 
> > +ROOTFS_POSTPROCESS_COMMAND += "add_machine_name_loop_back;"
> > +
> > +add_machine_name_loop_back() {
> > +    if [ -n ${MACHINE} ]; then
> > +         echo 127.0.1.1 "       "${MACHINE} >>
> > ${IMAGE_ROOTFS}${sysconfdir}/hosts +    fi
> > +}
> > +
> 
> I think in the earlier discussion the conclusion was that we do not want this 
> enabled by default, which the above will do.
> 
> The question I have is, if this isn't a good idea, is there a better solution?

These things belong to first time install/commissioning of the device
IMO. They are necessary operations but we do not have first time boot
scenario
Enrico Scholz - Aug. 5, 2014, 11:22 a.m.
sujith h <sujith.h-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> Is it ok to read from /etc/hostname and then have that in the /etc/hosts
> file, rather than using ${MACHINE}?
> ...
> +         echo 127.0.1.1 "       "${MACHINE} >> ${IMAGE_ROOTFS}${sysconfdir}/hosts

I do not see how this can be done while building the image or the
packages.  Both the hostname and the ip address can be configured at
runtime.  As this can happen dynamically e.g. by DHCP and can change
at every boot or even at runtime, there is no generic way (e.g. by
firstboot mechanisms) to add such entries.


Enrico
Koen Kooi - Aug. 5, 2014, 12:47 p.m.
Op 4 aug. 2014, om 15:57 heeft Sujith H <sujith.h@gmail.com> het volgende geschreven:

> From: Sujith H <Sujith_Haridasan@mentor.com>
> 
> If hostname is not added to /etc/hosts file then rpcinfo
> command fails when hostname is passed as argument. This was
> observed when rpcinfo command was tested on freescale target.
> Below was the output observed without this change.

Isn't this what nssmyhostname is for?
Sujith H - Aug. 5, 2014, 1:08 p.m.
On Tue, Aug 5, 2014 at 6:17 PM, Koen Kooi <koen@dominion.thruhere.net>
wrote:

>
> Op 4 aug. 2014, om 15:57 heeft Sujith H <sujith.h@gmail.com> het volgende
> geschreven:
>
> > From: Sujith H <Sujith_Haridasan@mentor.com>
> >
> > If hostname is not added to /etc/hosts file then rpcinfo
> > command fails when hostname is passed as argument. This was
> > observed when rpcinfo command was tested on freescale target.
> > Below was the output observed without this change.
>
> Isn't this what nssmyhostname is for?


Yes adding nss-myhostname would be the cleaner solution. Thanks Koen Kooi.

Patch

diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
index 82605f2..7a5a5c1 100644
--- a/meta/classes/image.bbclass
+++ b/meta/classes/image.bbclass
@@ -341,6 +341,14 @@  ssh_disable_dns_lookup () {
 	fi
 }
 
+ROOTFS_POSTPROCESS_COMMAND += "add_machine_name_loop_back;"
+
+add_machine_name_loop_back() {
+    if [ -n ${MACHINE} ]; then
+         echo 127.0.1.1 "       "${MACHINE} >> ${IMAGE_ROOTFS}${sysconfdir}/hosts
+    fi
+}
+
 # Enable postinst logging if debug-tweaks is enabled
 postinst_enable_logging () {
 	mkdir -p ${IMAGE_ROOTFS}${sysconfdir}/default