hostname-util: rework read_hostname_config() a bit
authorLennart Poettering <lennart@poettering.net>
Tue, 14 Nov 2017 18:51:06 +0000 (19:51 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 20 Nov 2017 15:43:15 +0000 (16:43 +0100)
commitf35cb39ed6fa8ad48bd3125c30bca7f310ef5788
treefd507f1e37bc864b7b7e338cf139b1dacb1e5eb8
parent9990ea0e59373c02b6bd64a5a4c860d2579f77db
hostname-util: rework read_hostname_config() a bit

First of all, let's rename it to read_etc_hostname(), to make clearer
what kind of configuration it actually reads: the file format defined in
/etc/hostname and nothing else.

Secondly: let's port this to use read_line(), i.e. the new way to read
lines from a file in a safe, bounded way.

Thirdly: let's strip leading/trailing whitespace from what we are
reading. Given that we are already pretty lenient what we read (comments
and empty lines), let's be permissive regarding whitespace too.

Fourthly: let's actually validate the hostname when reading it. So far
we tried to make it valid, but that's not always possible (for example,
we can't make an empty hostname valid, ever).
src/basic/hostname-util.c
src/basic/hostname-util.h
src/core/hostname-setup.c
src/hostname/hostnamed.c
src/test/test-hostname-util.c