diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2015-08-05 21:01:06 -0400 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2015-08-05 21:02:41 -0400 |
commit | 73974f6768ef5314a572eb93f5cfc7f0f29c9549 (patch) | |
tree | e95c0a5626290c79e7c31ac143e6c75a0f167d9d /src/hostname/hostnamectl.c | |
parent | 4306d66f594722a2fe44b034d3c68bfb864c6a76 (diff) | |
parent | 90365b043ab6a0d8100e0c37dea4ca9d6fdb4695 (diff) |
Merge branch 'hostnamectl-dot-v2'
Manual merge of https://github.com/systemd/systemd/pull/751.
Diffstat (limited to 'src/hostname/hostnamectl.c')
-rw-r--r-- | src/hostname/hostnamectl.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c index c996fc04a0..dcbad99ae9 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); + } else { + p = h = strdup(hostname); + if (!p) + return log_oom(); + + hostname_cleanup(hostname); } r = set_simple_string(bus, "SetPrettyHostname", p); |