summaryrefslogtreecommitdiff
path: root/src/hostname/hostnamectl.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/hostname/hostnamectl.c')
-rw-r--r--src/hostname/hostnamectl.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c
index 7945c86b5f..917fac2466 100644
--- a/src/hostname/hostnamectl.c
+++ b/src/hostname/hostnamectl.c
@@ -247,6 +247,26 @@ static int set_hostname(DBusConnection *bus, char **args, unsigned n) {
polkit_agent_open_if_enabled();
if (arg_set_pretty) {
+ const char *p;
+
+ /* If the passed hostname is already valid, then
+ * assume the user doesn't know anything about pretty
+ * hostnames, so let's unset the pretty hostname, and
+ * just set the passed hostname as static/dynamic
+ * hostname. */
+
+ if (hostname_is_valid(hostname))
+ p = "";
+ else {
+ p = hostname;
+
+ h = strdup(hostname);
+ if (!h)
+ return log_oom();
+
+ hostname = hostname_simplify(h);
+ }
+
r = bus_method_call_with_reply(
bus,
"org.freedesktop.hostname1",
@@ -255,17 +275,14 @@ static int set_hostname(DBusConnection *bus, char **args, unsigned n) {
"SetPrettyHostname",
&reply,
NULL,
- DBUS_TYPE_STRING, &hostname,
+ DBUS_TYPE_STRING, &p,
DBUS_TYPE_BOOLEAN, &interactive,
DBUS_TYPE_INVALID);
if (r < 0)
return r;
- h = strdup(hostname);
- if (!h)
- return log_oom();
-
- hostname = hostname_simplify(h);
+ dbus_message_unref(reply);
+ reply = NULL;
}
if (arg_set_static) {
@@ -283,6 +300,9 @@ static int set_hostname(DBusConnection *bus, char **args, unsigned n) {
if (r < 0)
return r;
+
+ dbus_message_unref(reply);
+ reply = NULL;
}
if (arg_set_transient) {