diff mbox series

[ovs-dev,1/3] ovs-ctl: fallback to "uname -n" for fetching hostname

Message ID 20181130073004.18051-2-zhouyousong@yunionyun.com
State Changes Requested
Headers show
Series build: patches from OpenWrt | expand

Commit Message

Yousong Zhou Nov. 30, 2018, 7:30 a.m. UTC
From: Yousong Zhou <yszhou4tech@gmail.com>

The command "hostname" is not available in OpenWrt by default.  Strace
result of hostname-3.13 on centos7 shows that bare "hostname" command
calls uname() to fetch node name.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
---
 utilities/ovs-ctl.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Aaron Conole Nov. 30, 2018, 3:23 p.m. UTC | #1
Yousong Zhou <yszhou4tech@gmail.com> writes:

> From: Yousong Zhou <yszhou4tech@gmail.com>
>
> The command "hostname" is not available in OpenWrt by default.  Strace
> result of hostname-3.13 on centos7 shows that bare "hostname" command
> calls uname() to fetch node name.
>
> Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
> ---
>  utilities/ovs-ctl.in | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/utilities/ovs-ctl.in b/utilities/ovs-ctl.in
> index e42f0f1e6..7f2b17b06 100644
> --- a/utilities/ovs-ctl.in
> +++ b/utilities/ovs-ctl.in
> @@ -40,7 +40,7 @@ set_hostname () {
>      # call this only after ovs-vswitchd is running.
>      hn="$(hostname -f)"
>      if test X$FULL_HOSTNAME = Xno; then
> -        hn="$(hostname)"
> +        hn="$(uname -n)"
>      fi

Should we also modify the call to 'hostname' above, too?  ie:

-     hn="$(hostname -f)"
+     hn="$(uname -n)"

I don't know since uname -n is always the same as hostname -f,
iirc.  That makes the option (FULL_HOSTNAME=no) look strange.

Actually, that makes me think that the hn="$(hostname)" might need to
have been 'hostname -s' - but I'm not sure.

>      ovs_vsctl set Open_vSwitch . external-ids:hostname="$hn"
>  }
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
Yousong Zhou Dec. 1, 2018, 2:20 a.m. UTC | #2
On Fri, 30 Nov 2018 at 23:23, Aaron Conole <aconole@redhat.com> wrote:
>
> Yousong Zhou <yszhou4tech@gmail.com> writes:
>
> > From: Yousong Zhou <yszhou4tech@gmail.com>
> >
> > The command "hostname" is not available in OpenWrt by default.  Strace
> > result of hostname-3.13 on centos7 shows that bare "hostname" command
> > calls uname() to fetch node name.
> >
> > Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
> > ---
> >  utilities/ovs-ctl.in | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/utilities/ovs-ctl.in b/utilities/ovs-ctl.in
> > index e42f0f1e6..7f2b17b06 100644
> > --- a/utilities/ovs-ctl.in
> > +++ b/utilities/ovs-ctl.in
> > @@ -40,7 +40,7 @@ set_hostname () {
> >      # call this only after ovs-vswitchd is running.
> >      hn="$(hostname -f)"
> >      if test X$FULL_HOSTNAME = Xno; then
> > -        hn="$(hostname)"
> > +        hn="$(uname -n)"
> >      fi
>
> Should we also modify the call to 'hostname' above, too?  ie:
>
> -     hn="$(hostname -f)"
> +     hn="$(uname -n)"
>
> I don't know since uname -n is always the same as hostname -f,
> iirc.  That makes the option (FULL_HOSTNAME=no) look strange.
>
> Actually, that makes me think that the hn="$(hostname)" might need to
> have been 'hostname -s' - but I'm not sure.

On my centos7 machine, `hostname -f` will try to form and verify fqdn
by reading "domain" from /etc/resolv.conf and doing dns query.  I
think the output of "uname -n" is same as with "sysctl -n
kernel.hostname"

                yousong
Aaron Conole Dec. 1, 2018, 6:05 p.m. UTC | #3
Yousong Zhou <yszhou4tech@gmail.com> writes:

> On Fri, 30 Nov 2018 at 23:23, Aaron Conole <aconole@redhat.com> wrote:
>>
>> Yousong Zhou <yszhou4tech@gmail.com> writes:
>>
>> > From: Yousong Zhou <yszhou4tech@gmail.com>
>> >
>> > The command "hostname" is not available in OpenWrt by default.  Strace
>> > result of hostname-3.13 on centos7 shows that bare "hostname" command
>> > calls uname() to fetch node name.
>> >
>> > Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
>> > ---
>> >  utilities/ovs-ctl.in | 2 +-
>> >  1 file changed, 1 insertion(+), 1 deletion(-)
>> >
>> > diff --git a/utilities/ovs-ctl.in b/utilities/ovs-ctl.in
>> > index e42f0f1e6..7f2b17b06 100644
>> > --- a/utilities/ovs-ctl.in
>> > +++ b/utilities/ovs-ctl.in
>> > @@ -40,7 +40,7 @@ set_hostname () {
>> >      # call this only after ovs-vswitchd is running.
>> >      hn="$(hostname -f)"
>> >      if test X$FULL_HOSTNAME = Xno; then
>> > -        hn="$(hostname)"
>> > +        hn="$(uname -n)"
>> >      fi
>>
>> Should we also modify the call to 'hostname' above, too?  ie:
>>
>> -     hn="$(hostname -f)"
>> +     hn="$(uname -n)"
>>
>> I don't know since uname -n is always the same as hostname -f,
>> iirc.  That makes the option (FULL_HOSTNAME=no) look strange.
>>
>> Actually, that makes me think that the hn="$(hostname)" might need to
>> have been 'hostname -s' - but I'm not sure.
>
> On my centos7 machine, `hostname -f` will try to form and verify fqdn
> by reading "domain" from /etc/resolv.conf and doing dns query.  I
> think the output of "uname -n" is same as with "sysctl -n
> kernel.hostname"

Still, I think the hostname call above should be reworked.  Maybe
something like:

  hn="$(uname -n)"
  if test X$FULL_HOSTNAME = Xyes; then
      hn=$(hostname -f)
  fi

Just a thought.  If hostname doesn't exist, then you're going to always
invoke it as-is.  Maybe I'm misunderstanding something, though.  WDYT?

>                 yousong
Yousong Zhou Dec. 2, 2018, 12:51 p.m. UTC | #4
On Sun, 2 Dec 2018 at 02:05, Aaron Conole <aconole@redhat.com> wrote:
>
> Yousong Zhou <yszhou4tech@gmail.com> writes:
>
> > On Fri, 30 Nov 2018 at 23:23, Aaron Conole <aconole@redhat.com> wrote:
> >>
> >> Yousong Zhou <yszhou4tech@gmail.com> writes:
> >>
> >> > From: Yousong Zhou <yszhou4tech@gmail.com>
> >> >
> >> > The command "hostname" is not available in OpenWrt by default.  Strace
> >> > result of hostname-3.13 on centos7 shows that bare "hostname" command
> >> > calls uname() to fetch node name.
> >> >
> >> > Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
> >> > ---
> >> >  utilities/ovs-ctl.in | 2 +-
> >> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >> >
> >> > diff --git a/utilities/ovs-ctl.in b/utilities/ovs-ctl.in
> >> > index e42f0f1e6..7f2b17b06 100644
> >> > --- a/utilities/ovs-ctl.in
> >> > +++ b/utilities/ovs-ctl.in
> >> > @@ -40,7 +40,7 @@ set_hostname () {
> >> >      # call this only after ovs-vswitchd is running.
> >> >      hn="$(hostname -f)"
> >> >      if test X$FULL_HOSTNAME = Xno; then
> >> > -        hn="$(hostname)"
> >> > +        hn="$(uname -n)"
> >> >      fi
> >>
> >> Should we also modify the call to 'hostname' above, too?  ie:
> >>
> >> -     hn="$(hostname -f)"
> >> +     hn="$(uname -n)"
> >>
> >> I don't know since uname -n is always the same as hostname -f,
> >> iirc.  That makes the option (FULL_HOSTNAME=no) look strange.
> >>
> >> Actually, that makes me think that the hn="$(hostname)" might need to
> >> have been 'hostname -s' - but I'm not sure.
> >
> > On my centos7 machine, `hostname -f` will try to form and verify fqdn
> > by reading "domain" from /etc/resolv.conf and doing dns query.  I
> > think the output of "uname -n" is same as with "sysctl -n
> > kernel.hostname"
>
> Still, I think the hostname call above should be reworked.  Maybe
> something like:
>
>   hn="$(uname -n)"
>   if test X$FULL_HOSTNAME = Xyes; then
>       hn=$(hostname -f)
>   fi
>
> Just a thought.  If hostname doesn't exist, then you're going to always
> invoke it as-is.  Maybe I'm misunderstanding something, though.  WDYT?

maybe at the beginning when this code was written the intent of
"hostname -f" was to make the name as "full" as possible so that it
can be uniquely identified in a larger scale from a different domain,
or from "external".  If that is the case, then "uname -n" should only
be used as a fallback in the heristics.

                yousong
Ben Pfaff Dec. 3, 2018, 9:09 p.m. UTC | #5
On Sun, Dec 02, 2018 at 08:51:09PM +0800, Yousong Zhou wrote:
> On Sun, 2 Dec 2018 at 02:05, Aaron Conole <aconole@redhat.com> wrote:
> >
> > Yousong Zhou <yszhou4tech@gmail.com> writes:
> >
> > > On Fri, 30 Nov 2018 at 23:23, Aaron Conole <aconole@redhat.com> wrote:
> > >>
> > >> Yousong Zhou <yszhou4tech@gmail.com> writes:
> > >>
> > >> > From: Yousong Zhou <yszhou4tech@gmail.com>
> > >> >
> > >> > The command "hostname" is not available in OpenWrt by default.  Strace
> > >> > result of hostname-3.13 on centos7 shows that bare "hostname" command
> > >> > calls uname() to fetch node name.
> > >> >
> > >> > Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
> > >> > ---
> > >> >  utilities/ovs-ctl.in | 2 +-
> > >> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > >> >
> > >> > diff --git a/utilities/ovs-ctl.in b/utilities/ovs-ctl.in
> > >> > index e42f0f1e6..7f2b17b06 100644
> > >> > --- a/utilities/ovs-ctl.in
> > >> > +++ b/utilities/ovs-ctl.in
> > >> > @@ -40,7 +40,7 @@ set_hostname () {
> > >> >      # call this only after ovs-vswitchd is running.
> > >> >      hn="$(hostname -f)"
> > >> >      if test X$FULL_HOSTNAME = Xno; then
> > >> > -        hn="$(hostname)"
> > >> > +        hn="$(uname -n)"
> > >> >      fi
> > >>
> > >> Should we also modify the call to 'hostname' above, too?  ie:
> > >>
> > >> -     hn="$(hostname -f)"
> > >> +     hn="$(uname -n)"
> > >>
> > >> I don't know since uname -n is always the same as hostname -f,
> > >> iirc.  That makes the option (FULL_HOSTNAME=no) look strange.
> > >>
> > >> Actually, that makes me think that the hn="$(hostname)" might need to
> > >> have been 'hostname -s' - but I'm not sure.
> > >
> > > On my centos7 machine, `hostname -f` will try to form and verify fqdn
> > > by reading "domain" from /etc/resolv.conf and doing dns query.  I
> > > think the output of "uname -n" is same as with "sysctl -n
> > > kernel.hostname"
> >
> > Still, I think the hostname call above should be reworked.  Maybe
> > something like:
> >
> >   hn="$(uname -n)"
> >   if test X$FULL_HOSTNAME = Xyes; then
> >       hn=$(hostname -f)
> >   fi
> >
> > Just a thought.  If hostname doesn't exist, then you're going to always
> > invoke it as-is.  Maybe I'm misunderstanding something, though.  WDYT?
> 
> maybe at the beginning when this code was written the intent of
> "hostname -f" was to make the name as "full" as possible so that it
> can be uniquely identified in a larger scale from a different domain,
> or from "external".  If that is the case, then "uname -n" should only
> be used as a fallback in the heristics.

I think that was the intent.

This might be a reasonable way to do it, which would deal with hostname
not being available:

if X$FULL_HOSTNAME = Xyes; then
    hn=$(hostname -f) || hn=$(uname -n)
else
    hn=$(uname -n)
fi
diff mbox series

Patch

diff --git a/utilities/ovs-ctl.in b/utilities/ovs-ctl.in
index e42f0f1e6..7f2b17b06 100644
--- a/utilities/ovs-ctl.in
+++ b/utilities/ovs-ctl.in
@@ -40,7 +40,7 @@  set_hostname () {
     # call this only after ovs-vswitchd is running.
     hn="$(hostname -f)"
     if test X$FULL_HOSTNAME = Xno; then
-        hn="$(hostname)"
+        hn="$(uname -n)"
     fi
     ovs_vsctl set Open_vSwitch . external-ids:hostname="$hn"
 }