summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-05-07 20:55:11 +0200
committerLennart Poettering <lennart@poettering.net>2013-05-07 20:56:41 +0200
commite724b0639c43c2821613fc4f7f755f87c49a22e8 (patch)
tree1c981e6dd6521cd1188abb3ab2536279b5bc3747 /src/shared
parent0b95a21bd70f63fc57f62020ae84e467712d69f2 (diff)
hostname: only suppress setting of pretty hostname if it is non-equal to the static hostname and if the static hostname is set, too
https://bugzilla.redhat.com/show_bug.cgi?id=957814
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/util.c17
-rw-r--r--src/shared/util.h2
2 files changed, 12 insertions, 7 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 00d3ace616..673e0da6b6 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -3838,24 +3838,29 @@ bool hostname_is_valid(const char *s) {
return true;
}
-char* hostname_cleanup(char *s) {
+char* hostname_cleanup(char *s, bool lowercase) {
char *p, *d;
bool dot;
for (p = s, d = s, dot = true; *p; p++) {
if (*p == '.') {
- if (dot || p[1] == 0)
+ if (dot)
continue;
+ *(d++) = '.';
dot = true;
- } else
+ } else if (hostname_valid_char(*p)) {
+ *(d++) = lowercase ? tolower(*p) : *p;
dot = false;
+ }
- if (hostname_valid_char(*p))
- *(d++) = *p;
}
- *d = 0;
+ if (dot && d > s)
+ d[-1] = 0;
+ else
+ *d = 0;
+
strshorten(s, HOST_NAME_MAX);
return s;
diff --git a/src/shared/util.h b/src/shared/util.h
index 7ef46e8f1e..64e63b8c07 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -411,7 +411,7 @@ bool nulstr_contains(const char*nulstr, const char *needle);
bool plymouth_running(void);
bool hostname_is_valid(const char *s) _pure_;
-char* hostname_cleanup(char *s);
+char* hostname_cleanup(char *s, bool lowercase);
char* strshorten(char *s, size_t l);