summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-07-27 22:30:06 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-08-05 20:49:21 -0400
commit17eb9a9ddba3f03fcba33445c1c1eedeb948da04 (patch)
treeae0768463007ff944dc0e3bfb2def4e005ce0be3 /src
parent79f17ea6f8d885da063f50d966891adaee236b26 (diff)
hostnamectl: allow trailing dot on fqdn
When the user requests to set hostname, and we are setting both pretty and static hostnames, and the name is a valid FQDN, we use it as the static hostname, and unset the pretty hostname. The change is that a FQDN with a trailing dot is accepted and ignored. https://bugzilla.redhat.com/show_bug.cgi?id=1238246 Lowercasing of the static name is not done anymore. $ hostnamectl set-hostname Foobar. => static is "Foobar", pretty is "Foobar." $ hostnamectl set-hostname Foobar.org. => static is "Foobar.org", pretty is unset $ hostnamectl set-hostname Foobar.org.. => static is "Foobar.org", pretty is "Foobar.org.."
Diffstat (limited to 'src')
-rw-r--r--src/hostname/hostnamectl.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c
index c996fc04a0..d194e9b629 100644
--- a/src/hostname/hostnamectl.c
+++ b/src/hostname/hostnamectl.c
@@ -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);