mirror of
https://github.com/systemd/systemd.git
synced 2025-01-11 09:18:07 +03:00
hostnamectl: if somebody invokes 'hostnamectl set-hostname' with a valid internet hostname unset the pretty name
If people are unaware or uninterested in the concept of pretty host names, and simply invoke "hostnamectl set-hostname" for a valid internet host name, then use this as indication to unset the pretty host name and only set the static/dynamic one. This also allows fqdn, hence "hostnamectl set-hostname www.foobar.com" will just work if people really insist on using fqdns as hostnames.
This commit is contained in:
parent
fec6fc6bae
commit
fda2c5d28b
@ -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) {
|
||||
|
@ -444,7 +444,7 @@ static DBusHandlerResult hostname_message_handler(
|
||||
return bus_send_error_reply(connection, message, NULL, r);
|
||||
}
|
||||
|
||||
log_info("Changed host name to '%s'", strempty(data[PROP_HOSTNAME]));
|
||||
log_info("Changed host name to '%s'", strna(data[PROP_HOSTNAME]));
|
||||
|
||||
changed = bus_properties_changed_new(
|
||||
"/org/freedesktop/hostname1",
|
||||
@ -498,7 +498,7 @@ static DBusHandlerResult hostname_message_handler(
|
||||
return bus_send_error_reply(connection, message, NULL, r);
|
||||
}
|
||||
|
||||
log_info("Changed static host name to '%s'", strempty(data[PROP_STATIC_HOSTNAME]));
|
||||
log_info("Changed static host name to '%s'", strna(data[PROP_STATIC_HOSTNAME]));
|
||||
|
||||
changed = bus_properties_changed_new(
|
||||
"/org/freedesktop/hostname1",
|
||||
@ -574,7 +574,7 @@ static DBusHandlerResult hostname_message_handler(
|
||||
|
||||
log_info("Changed %s to '%s'",
|
||||
k == PROP_PRETTY_HOSTNAME ? "pretty host name" :
|
||||
k == PROP_CHASSIS ? "chassis" : "icon name", strempty(data[k]));
|
||||
k == PROP_CHASSIS ? "chassis" : "icon name", strna(data[k]));
|
||||
|
||||
changed = bus_properties_changed_new(
|
||||
"/org/freedesktop/hostname1",
|
||||
|
Loading…
Reference in New Issue
Block a user