chiark / gitweb /
hostname: only suppress setting of pretty hostname if it is non-equal to the static...
authorLennart Poettering <lennart@poettering.net>
Tue, 7 May 2013 18:55:11 +0000 (20:55 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 7 May 2013 18:56:41 +0000 (20:56 +0200)
https://bugzilla.redhat.com/show_bug.cgi?id=957814

src/core/hostname-setup.c
src/hostname/hostnamectl.c
src/journal/journal-gatewayd.c
src/journal/journalctl.c
src/nspawn/nspawn.c
src/shared/util.c
src/shared/util.h

index ac508af122a3104c4cad7b049451b2e8e082527d..8aa1cff1d30f23ad1a42826a487a7e8540a11beb 100644 (file)
@@ -42,7 +42,7 @@ static int read_and_strip_hostname(const char *path, char **hn) {
         if (r < 0)
                 return r;
 
         if (r < 0)
                 return r;
 
-        hostname_cleanup(s);
+        hostname_cleanup(s, false);
 
         if (isempty(s)) {
                 free(s);
 
         if (isempty(s)) {
                 free(s);
index 1c9043534a316c5a5afff4172cfbada675f7aa3b..a1e1bd84437afb0cb79a04cf992f17f60c0e1cf3 100644 (file)
@@ -213,26 +213,6 @@ static int show_status(DBusConnection *bus, char **args, unsigned n) {
         return 0;
 }
 
         return 0;
 }
 
-static char* hostname_simplify(char *s) {
-        char *p, *d;
-
-        for (p = s, d = s; *p; p++) {
-                if ((*p >= 'a' && *p <= 'z') ||
-                    (*p >= '0' && *p <= '9') ||
-                    *p == '-' || *p == '_')
-                        *(d++) = *p;
-                else if (*p >= 'A' && *p <= 'Z')
-                        *(d++) = *p - 'A' + 'a';
-                else if (*p == ' ')
-                        *(d++) = '-';
-        }
-
-        *d = 0;
-
-        strshorten(s, HOST_NAME_MAX);
-        return s;
-}
-
 static int set_hostname(DBusConnection *bus, char **args, unsigned n) {
         _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
         dbus_bool_t interactive = true;
 static int set_hostname(DBusConnection *bus, char **args, unsigned n) {
         _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
         dbus_bool_t interactive = true;
@@ -254,16 +234,17 @@ static int set_hostname(DBusConnection *bus, char **args, unsigned n) {
                  * just set the passed hostname as static/dynamic
                  * hostname. */
 
                  * just set the passed hostname as static/dynamic
                  * hostname. */
 
-                if (hostname_is_valid(hostname))
+                h = strdup(hostname);
+                if (!h)
+                        return log_oom();
+
+                hostname_cleanup(h, true);
+
+                if (arg_set_static && streq(h, hostname))
                         p = "";
                 else {
                         p = hostname;
                         p = "";
                 else {
                         p = hostname;
-
-                        h = strdup(hostname);
-                        if (!h)
-                                return log_oom();
-
-                        hostname = hostname_simplify(h);
+                        hostname = h;
                 }
 
                 r = bus_method_call_with_reply(
                 }
 
                 r = bus_method_call_with_reply(
index 51a938b79e99d3e303f7757b60fb8c99593bca5d..745f45f932c1b78ffa2ccc6c79e8de282307058d 100644 (file)
@@ -839,7 +839,7 @@ static int request_handler_machine(
                      "\"cutoff_to_realtime\" : \"%llu\" }\n",
                      SD_ID128_FORMAT_VAL(mid),
                      SD_ID128_FORMAT_VAL(bid),
                      "\"cutoff_to_realtime\" : \"%llu\" }\n",
                      SD_ID128_FORMAT_VAL(mid),
                      SD_ID128_FORMAT_VAL(bid),
-                     hostname_cleanup(hostname),
+                     hostname_cleanup(hostname, false),
                      os_name ? os_name : "Linux",
                      v ? v : "bare",
                      (unsigned long long) usage,
                      os_name ? os_name : "Linux",
                      v ? v : "bare",
                      (unsigned long long) usage,
index d1b201beba24918457223791a41b3d9814ee9e96..409f0822766e3be61b855fc7604882dd02a6fa46 100644 (file)
@@ -835,7 +835,7 @@ static int setup_keys(void) {
                 hn = gethostname_malloc();
 
                 if (hn) {
                 hn = gethostname_malloc();
 
                 if (hn) {
-                        hostname_cleanup(hn);
+                        hostname_cleanup(hn, false);
                         fprintf(stderr, "\nThe keys have been generated for host %s/" SD_ID128_FORMAT_STR ".\n", hn, SD_ID128_FORMAT_VAL(machine));
                 } else
                         fprintf(stderr, "\nThe keys have been generated for host " SD_ID128_FORMAT_STR ".\n", SD_ID128_FORMAT_VAL(machine));
                         fprintf(stderr, "\nThe keys have been generated for host %s/" SD_ID128_FORMAT_STR ".\n", hn, SD_ID128_FORMAT_VAL(machine));
                 } else
                         fprintf(stderr, "\nThe keys have been generated for host " SD_ID128_FORMAT_STR ".\n", SD_ID128_FORMAT_VAL(machine));
index a58cbec38a4bd1fe8d829a7d9d7f8bf455bfdf75..09153c87ce2694de46835467aa19f99838ae75b8 100644 (file)
@@ -1267,7 +1267,7 @@ int main(int argc, char *argv[]) {
                         goto finish;
                 }
 
                         goto finish;
                 }
 
-                hostname_cleanup(arg_machine);
+                hostname_cleanup(arg_machine, false);
                 if (isempty(arg_machine)) {
                         log_error("Failed to determine machine name automatically, please use -M.");
                         goto finish;
                 if (isempty(arg_machine)) {
                         log_error("Failed to determine machine name automatically, please use -M.");
                         goto finish;
index 00d3ace6167d85864e1d2a7697272126ea6c2227..673e0da6b69f38112708581ff81abe65a1675c1b 100644 (file)
@@ -3838,24 +3838,29 @@ bool hostname_is_valid(const char *s) {
         return true;
 }
 
         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 == '.') {
         char *p, *d;
         bool dot;
 
         for (p = s, d = s, dot = true; *p; p++) {
                 if (*p == '.') {
-                        if (dot || p[1] == 0)
+                        if (dot)
                                 continue;
 
                                 continue;
 
+                        *(d++) = '.';
                         dot = true;
                         dot = true;
-                } else
+                } else if (hostname_valid_char(*p)) {
+                        *(d++) = lowercase ? tolower(*p) : *p;
                         dot = false;
                         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;
         strshorten(s, HOST_NAME_MAX);
 
         return s;
index 7ef46e8f1ede68c2b38b2b46143550ca7d00176f..64e63b8c0764ca69ce56f02e0473e5118606ba35 100644 (file)
@@ -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_;
 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);
 
 
 char* strshorten(char *s, size_t l);