]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/hostname/hostnamectl.c
hostnamectl: allow trailing dot on fqdn
[thirdparty/systemd.git] / src / hostname / hostnamectl.c
index c996fc04a08aefcba6a61c7697f7df33e99cb080..d194e9b629a54b175136f45a99a69fb06511ace8 100644 (file)
@@ -252,7 +252,7 @@ static int set_simple_string(sd_bus *bus, const char *method, const char *value)
 
 static int set_hostname(sd_bus *bus, char **args, unsigned n) {
         _cleanup_free_ char *h = NULL;
-        const char *hostname = args[1];
+        char *hostname = args[1];
         int r;
 
         assert(args);
@@ -270,17 +270,16 @@ static int set_hostname(sd_bus *bus, char **args, unsigned n) {
                  * just set the passed hostname as static/dynamic
                  * hostname. */
 
-                h = strdup(hostname);
-                if (!h)
-                        return log_oom();
-
-                hostname_cleanup(h, true);
-
-                if (arg_static && streq(h, hostname))
+                if (arg_static && hostname_is_valid(hostname, true)) {
                         p = "";
-                else {
-                        p = hostname;
-                        hostname = h;
+                        /* maybe get rid of trailing dot */
+                        hostname = hostname_cleanup(hostname, false);
+                } else {
+                        p = h = strdup(hostname);
+                        if (!p)
+                                return log_oom();
+
+                        hostname_cleanup(hostname, false);
                 }
 
                 r = set_simple_string(bus, "SetPrettyHostname", p);