[arch-projects] [PATCH 1/7] config: add /etc/hostname support

Dave Reisner d at falconindy.com
Wed Oct 26 23:48:27 EDT 2011


On Thu, Oct 27, 2011 at 11:36:01AM +0800, lolilolicon wrote:
> On Thu, Oct 27, 2011 at 7:44 AM, Dave Reisner <d at falconindy.com> wrote:
> > On Thu, Oct 27, 2011 at 01:38:27AM +0200, Tom Gundersen wrote:
> >> If /etc/hostname is non-empty its contents is assumed to be the hostname.
> >> This takes precedence over HOSTNAME in rc.conf.
> >>
> >> Signed-off-by: Tom Gundersen <teg at jklm.no>
> >> ---
> >>  rc.sysinit |    3 +++
> >>  1 files changed, 3 insertions(+), 0 deletions(-)
> >>
> >> diff --git a/rc.sysinit b/rc.sysinit
> >> index dffea4d..3e5fec9 100755
> >> --- a/rc.sysinit
> >> +++ b/rc.sysinit
> >> @@ -232,6 +232,9 @@ RANDOM_SEED=/var/lib/misc/random-seed
> >>  # Remove leftover files
> >>  remove_leftover
> >>
> >> +if [[ -s /etc/hostname ]]; then
> >> +     HOSTNAME=$(cat /etc/hostname)
> >
> > No need to fork. This should be a one line file.
> >
> > read -r HOSTNAME < /etc/hostname
> >
> 
> If /etc/hostname does not end with a newline, `read' will return 1.
> Not sure if it matters here, but worth mentioning.
> 
> How about, HOSTNAME=$(< /etc/hostname)
> 

read returns 1 on EOF, too. Yes, we probably should cater to special
people who want to bloat their /etc/hostname.

IFS=$'\n' read -rd '' HOSTNAME </etc/hostname

d


More information about the arch-projects mailing list