diff options
author | Martin Pitt <martin.pitt@ubuntu.com> | 2015-05-19 07:49:56 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-05-19 12:18:08 +0200 |
commit | 139e5336286c37d9d4a2df01931ba0a86abbac69 (patch) | |
tree | 3edcfb5098607cca83f3139260002e5a545152ae /src/core/hostname-setup.c | |
parent | e861098bf22d8e65c3b2589e7ca056e720a06483 (diff) |
hostname: Allow comments in /etc/hostname
The hostname(1) tool allows comments in /etc/hostname. Introduce a new
read_hostname_config() in hostname-util which reads a hostname configuration
file like /etc/hostname, strips out comments, whitespace, and cleans the
hostname. Use it in hostname-setup.c and hostnamed and remove duplicated code.
Update hostname manpage. Add tests.
https://launchpad.net/bugs/1053048
Diffstat (limited to 'src/core/hostname-setup.c')
-rw-r--r-- | src/core/hostname-setup.c | 24 |
1 files changed, 1 insertions, 23 deletions
diff --git a/src/core/hostname-setup.c b/src/core/hostname-setup.c index 217f201d05..932ddbf95a 100644 --- a/src/core/hostname-setup.c +++ b/src/core/hostname-setup.c @@ -30,35 +30,13 @@ #include "hostname-util.h" #include "hostname-setup.h" -static int read_and_strip_hostname(const char *path, char **hn) { - char *s; - int r; - - assert(path); - assert(hn); - - r = read_one_line_file(path, &s); - if (r < 0) - return r; - - hostname_cleanup(s, false); - - if (isempty(s)) { - free(s); - return -ENOENT; - } - - *hn = s; - return 0; -} - int hostname_setup(void) { int r; _cleanup_free_ char *b = NULL; const char *hn; bool enoent = false; - r = read_and_strip_hostname("/etc/hostname", &b); + r = read_hostname_config("/etc/hostname", &b); if (r < 0) { if (r == -ENOENT) enoent = true; |