cvs commit: src/etc/rc.d hostname

Yar Tikhiy yar at comp.chem.msu.su
Mon Feb 12 12:09:14 UTC 2007


On Sun, Feb 11, 2007 at 09:44:38PM -0600, Brooks Davis wrote:
> On Sun, Feb 11, 2007 at 11:53:17AM +0300, Yar Tikhiy wrote:
> > On Sat, Feb 10, 2007 at 08:52:28PM +0000, Ceri Davies wrote:
> > > On Sat, Feb 10, 2007 at 01:13:33PM +0000, Yar Tikhiy wrote:
> > > > yar         2007-02-10 13:13:33 UTC
> > > > 
> > > >   FreeBSD src repository
> > > > 
> > > >   Modified files:
> > > >     etc/rc.d             hostname 
> > > >   Log:
> > > >   Handle the case when the admin forgot to set $hostname,
> > > >   which can happen in new installations: advise to set the
> > > >   variable and refer to rc.conf(5).
> > > 
> > > Isn't it possible for the hostname to come via DHCP?  How does this
> > > behave in that case (or rather, I can see how it behaves; is that the
> > > right thing)?
> > 
> > I've never played with setting the hostname via DHCP.  In my change,
> > I just tried not to break the existing code related to DHCP.  Perhaps
> > someone using DHCP to get the hostname could shed light on the topic.
> 
> This appears mostly harmless for systems that get their hostname via
> DHCP.  They will get a warning, but it will otherwise work.

Now I see.  The code getting $hostname via kenv from dhcp.host-name
is for the case when the host was booted via PXE.  OTOH, a usual
DHCP client will run dhclient when it comes to setting up network
interfaces, i.e., after /etc/rc.d/hostname.  Perhaps we need
a way to indicate that the hostname will be assigned automatically
and the nagging message shouldn't be emitted.  E.g., in rc.conf:

hostname="DHCP"

I have no idea how many Unix hosts allow their hostname to be set
via DHCP.  I prefer to think that a Unix host is like a good ship:
it never changes its name while furrowing the network seas.  A DHCP
assigned hostname better fits crippled hosts such as diskless
stations etc.

> -- Brooks
> 
> > > > | @@ -58,7 +58,16 @@ hostname_start()
> > > > |  		fi
> > > > |  	fi
> > > > |  
> > > > | -	/bin/hostname ${hostname}
> > > > | +	# Have we got a hostname yet?
> > > > | +	#
> > > > | +	if [ -z "${hostname}" ]; then
> > > > | +		warn "\$hostname is not set -- see ${rcvar_manpage}."
> > > > | +		return
> > > > | +	fi
> > > > | +
> > > > | +	# All right, it is safe to invoke hostname(1) now.
> > > > | +	#
> > > > | +	/bin/hostname "${hostname}"
> > > > |  	echo "Setting hostname: `hostname`."
> > > 
> > > Are the backticks necessary here?  Why don't we use ${hostname}?
> > 
> > Thus we determine what name has actually been set.  Our doing so
> > reeks of paranoia, of course. :-)  Perhaps a better ordering would
> > be:
> > 
> > echo "Setting hostname: ${hostname}."
> > /bin/hostname "${hostname}"
> > 
> > So possible error messages will follow the introductory statement,
> > which makes more sense.  Any objecttions?
> > 
> > -- 
> > Yar
> > 



-- 
Yar


More information about the cvs-all mailing list