summaryrefslogtreecommitdiff
path: root/src/hostname-setup.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/hostname-setup.c')
-rw-r--r--src/hostname-setup.c37
1 files changed, 7 insertions, 30 deletions
diff --git a/src/hostname-setup.c b/src/hostname-setup.c
index e9869bb4df..ab49767045 100644
--- a/src/hostname-setup.c
+++ b/src/hostname-setup.c
@@ -40,25 +40,8 @@
#define FILENAME "/etc/conf.d/hostname"
#endif
-static char* strip_bad_chars(char *s) {
- char *p, *d;
-
- for (p = s, d = s; *p; p++)
- if ((*p >= 'a' && *p <= 'z') ||
- (*p >= 'A' && *p <= 'Z') ||
- (*p >= '0' && *p <= '9') ||
- *p == '-' ||
- *p == '_' ||
- *p == '.')
- *(d++) = *p;
-
- *d = 0;
-
- return s;
-}
-
static int read_and_strip_hostname(const char *path, char **hn) {
- char *s, *k;
+ char *s;
int r;
assert(path);
@@ -67,20 +50,14 @@ static int read_and_strip_hostname(const char *path, char **hn) {
if ((r = read_one_line_file(path, &s)) < 0)
return r;
- k = strdup(strstrip(s));
- free(s);
-
- if (!k)
- return -ENOMEM;
-
- strip_bad_chars(k);
+ hostname_cleanup(s);
- if (k[0] == 0) {
- free(k);
+ if (isempty(s)) {
+ free(s);
return -ENOENT;
}
- *hn = k;
+ *hn = s;
return 0;
}
@@ -118,9 +95,9 @@ static int read_distro_hostname(char **hn) {
goto finish;
}
- strip_bad_chars(k);
+ hostname_cleanup(k);
- if (k[0] == 0) {
+ if (isempty(k)) {
free(k);
r = -ENOENT;
goto finish;