From 139e5336286c37d9d4a2df01931ba0a86abbac69 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Tue, 19 May 2015 07:49:56 +0200 Subject: 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 --- src/core/hostname-setup.c | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) (limited to 'src/core/hostname-setup.c') 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; -- cgit v1.2.3-54-g00ecf