[Toybox] Add -b and -F arguments to hostname

Paul Barker paul at paulbarker.me.uk
Wed May 4 11:07:19 PDT 2016


On Wed, 4 May 2016 04:11:05 -0500
Rob Landley <rob at landley.net> wrote:

> On 05/01/2016 01:56 PM, Paul Barker wrote:
> > Hi all,
> > 
> > I've attached a patch to add -b and -F arguments to the hostname
> > program within toybox. These options are used by the
> > '/etc/init.d/hostname.sh' init script in an image built with
> > OpenEmbedded. With these options added, the hostname is set
> > correctly during boot.
> > 
> > I've tried to keep the new code concise and followed the style used
> > elsewhere in toybox. Hopefully it won't need much cleanup.
> 
> It passed an initial sniff test and I applied it as-is, now I'm going
> through and doing whitespace tweaks and such. (Put a blank line
> between variable declarations and non-declaration code, etc.)
> 
> I _think_ you're trimming trailing whitespace because readfile() gets
> a newline? (Elliott added chomp() to lib/lib.c to trim trailing
> newlines.)

Yes, the /etc/hostname file ends in a newline on my system and
readfile() picked that up.

> 
> Hmmm... Ok, there's a difference between this one and ubuntu's: if I
> do:
> 
>   hostname -bF <(echo "")
> 
> The ubuntu version produces no output (but doesn't change the
> existingname either), and this version says "driftwood" (I.E. prints
> the old name).
> 
> I think I prefer my behavior for that. Neither is quite... clear. (-F
> said to chagne to an empty name, is that an error in the presence of
> -b? Should it replace the existing name with "localhost"?)

The spirit of the -b argument is that it can be used at boot time to
ensure that the hostname isn't left blank even if something goes wrong.
It doesn't seem to be very clearly specified.

> 
> Eh, hit it with a thorough test suite. (The current hostname test is
> useless, I should add a real one. Except, hmmm... How do I _clear_ the
> hostname so that -b has something to do?)

Running `hostname ""` clears the hostname for me.

> 
> I fluffed up the README a bit, let me know if I missed anything.

Contributing guidelines in the README now look good.

Many Thanks,
Paul Barker



More information about the Toybox mailing list