[arch-projects] [PATCH 1/7] config: add /etc/hostname support
lolilolicon
lolilolicon at gmail.com
Thu Oct 27 00:35:46 EDT 2011
On Thu, Oct 27, 2011 at 11:48 AM, Dave Reisner <d at falconindy.com> wrote:
> 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
Presumably there won't be any liternal NUL in /etc/hostname, so the above:
- strips the leading and traling newlines, and assign everything in
between to HOSTNAME.
- always returns 1
My question is, technically, what characters are allowed in HOSTNAME?
Is newline allowed? How about NUL?
>
> d
>
More information about the arch-projects
mailing list