summaryrefslogtreecommitdiff
path: root/src/grp-hostname/hostnamectl
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-12-17 03:11:52 -0500
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-12-17 03:11:52 -0500
commitb849891b5dde5ee14ab8b7b7db74e65a4a38d993 (patch)
tree29bb0e6fda9b4b170041913de495da057bbe3621 /src/grp-hostname/hostnamectl
parent004efebf9cc559ea131bb9460ee0ee198e2d5da7 (diff)
parent881228ff72434a0e3401a16bd87f179ef0ab1619 (diff)
Merge branch 'notsystemd/postmove' into notsystemd/master
# Conflicts: # src/grp-journal/libjournal-core/.gitignore # src/grp-system/libcore/include/core/mount.h
Diffstat (limited to 'src/grp-hostname/hostnamectl')
-rw-r--r--src/grp-hostname/hostnamectl/hostnamectl.c36
-rw-r--r--src/grp-hostname/hostnamectl/hostnamectl.xml43
2 files changed, 34 insertions, 45 deletions
diff --git a/src/grp-hostname/hostnamectl/hostnamectl.c b/src/grp-hostname/hostnamectl/hostnamectl.c
index c5f702087d..d6da61879b 100644
--- a/src/grp-hostname/hostnamectl/hostnamectl.c
+++ b/src/grp-hostname/hostnamectl/hostnamectl.c
@@ -251,7 +251,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;
- char *hostname = args[1];
+ const char *hostname = args[1];
int r;
assert(args);
@@ -263,27 +263,29 @@ static int set_hostname(sd_bus *bus, char **args, unsigned n) {
if (arg_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
+ /* 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 (arg_static && hostname_is_valid(hostname, true)) {
- p = "";
- /* maybe get rid of trailing dot */
- hostname = hostname_cleanup(hostname);
- } else {
- p = h = strdup(hostname);
- if (!p)
- return log_oom();
-
- hostname_cleanup(hostname);
- }
+ if (arg_static && hostname_is_valid(hostname, true))
+ p = ""; /* No pretty hostname (as it is redundant), just a static one */
+ else
+ p = hostname; /* Use the passed name as pretty hostname */
r = set_simple_string(bus, "SetPrettyHostname", p);
if (r < 0)
return r;
+
+ /* Now that we set the pretty hostname, let's clean up the parameter and use that as static
+ * hostname. If the hostname was already valid as static hostname, this will only chop off the trailing
+ * dot if there is one. If it was not valid, then it will be made fully valid by truncating, dropping
+ * multiple dots, and dropping weird chars. Note that we clean the name up only if we also are
+ * supposed to set the pretty name. If the pretty name is not being set we assume the user knows what
+ * he does and pass the name as-is. */
+ h = strdup(hostname);
+ if (!h)
+ return log_oom();
+
+ hostname = hostname_cleanup(h); /* Use the cleaned up name as static hostname */
}
if (arg_static) {
diff --git a/src/grp-hostname/hostnamectl/hostnamectl.xml b/src/grp-hostname/hostnamectl/hostnamectl.xml
index 60004e9d04..9e1b593e6d 100644
--- a/src/grp-hostname/hostnamectl/hostnamectl.xml
+++ b/src/grp-hostname/hostnamectl/hostnamectl.xml
@@ -71,10 +71,9 @@
set, and is valid (something other than localhost), then the
transient hostname is not used.</para>
- <para>Note that the pretty hostname has little restrictions on the
- characters used, while the static and transient hostnames are
- limited to the usually accepted characters of Internet domain
- names.</para>
+ <para>Note that the pretty hostname has little restrictions on the characters and length used, while the static and
+ transient hostnames are limited to the usually accepted characters of Internet domain names, and 64 characters at
+ maximum (the latter being a Linux limitation).</para>
<para>The static hostname is stored in
<filename>/etc/hostname</filename>, see
@@ -107,15 +106,11 @@
<term><option>--transient</option></term>
<term><option>--pretty</option></term>
- <listitem><para>If <command>status</command> is used (or no
- explicit command is given) and one of those fields is given,
- <command>hostnamectl</command> will print out just this
- selected hostname.</para>
+ <listitem><para>If <command>status</command> is invoked (or no explicit command is given) and one of these
+ switches is specified, <command>hostnamectl</command> will print out just this selected hostname.</para>
- <para>If used with <command>set-hostname</command>, only the
- selected hostname(s) will be updated. When more than one of
- those options is used, all the specified hostnames will be
- updated. </para></listitem>
+ <para>If used with <command>set-hostname</command>, only the selected hostname(s) will be updated. When more
+ than one of these switches are specified, all the specified hostnames will be updated. </para></listitem>
</varlistentry>
<xi:include href="user-system-options.xml" xpointer="host" />
@@ -139,22 +134,14 @@
<varlistentry>
<term><command>set-hostname <replaceable>NAME</replaceable></command></term>
- <listitem><para>Set the system hostname to
- <replaceable>NAME</replaceable>. By default, this will alter
- the pretty, the static, and the transient hostname alike;
- however, if one or more of <option>--static</option>,
- <option>--transient</option>, <option>--pretty</option> are
- used, only the selected hostnames are changed. If the pretty
- hostname is being set, and static or transient are being set
- as well, the specified hostname will be simplified in regards
- to the character set used before the latter are updated. This
- is done by replacing spaces with <literal>-</literal> and
- removing special characters. This ensures that the pretty and
- the static hostname are always closely related while still
- following the validity rules of the specific name. This
- simplification of the hostname string is not done if only the
- transient and/or static host names are set, and the pretty
- host name is left untouched.</para>
+ <listitem><para>Set the system hostname to <replaceable>NAME</replaceable>. By default, this will alter the
+ pretty, the static, and the transient hostname alike; however, if one or more of <option>--static</option>,
+ <option>--transient</option>, <option>--pretty</option> are used, only the selected hostnames are changed. If
+ the pretty hostname is being set, and static or transient are being set as well, the specified hostname will be
+ simplified in regards to the character set used before the latter are updated. This is done by removing special
+ characters and spaces. This ensures that the pretty and the static hostname are always closely related while
+ still following the validity rules of the specific name. This simplification of the hostname string is not done
+ if only the transient and/or static host names are set, and the pretty host name is left untouched.</para>
<para>Pass the empty string <literal></literal> as the
hostname to reset the selected hostnames to their default