mirror of
https://github.com/systemd/systemd.git
synced 2024-11-27 04:03:36 +08:00
hostnamed: rename FallbackHostname to DefaultHostname
This follows the addition of DEFAULT_HOSTNAME= in os-release. The distinction between the value from os-release or the env var and the compile-time setting is not made in the api: HostnameSource is "default" is all cases. I think that this level of detail is not needed, because the users of this mostly care whether the hostname was set by user configuration or not.
This commit is contained in:
parent
e7637751c4
commit
8770c8135b
4
NEWS
4
NEWS
@ -184,8 +184,8 @@ CHANGES WITH 248:
|
||||
ignored. The goal is to honour configuration as specified by the
|
||||
user.
|
||||
|
||||
* systemd-hostnamed now exports the fallback hostname and the source of
|
||||
the configured hostname ("static", "transient", or "fallback") as
|
||||
* systemd-hostnamed now exports the default hostname and the source of
|
||||
the configured hostname ("static", "transient", or "default") as
|
||||
D-Bus properties.
|
||||
|
||||
* systemd-hostnamed now exports the HardwareVendor and HardwareModel
|
||||
|
@ -63,7 +63,7 @@ node /org/freedesktop/hostname1 {
|
||||
readonly s StaticHostname = '...';
|
||||
readonly s PrettyHostname = '...';
|
||||
@org.freedesktop.DBus.Property.EmitsChangedSignal("const")
|
||||
readonly s FallbackHostname = '...';
|
||||
readonly s DefaultHostname = '...';
|
||||
readonly s HostnameSource = '...';
|
||||
readonly s IconName = '...';
|
||||
readonly s Chassis = '...';
|
||||
@ -124,7 +124,7 @@ node /org/freedesktop/hostname1 {
|
||||
|
||||
<variablelist class="dbus-property" generated="True" extra-ref="PrettyHostname"/>
|
||||
|
||||
<variablelist class="dbus-property" generated="True" extra-ref="FallbackHostname"/>
|
||||
<variablelist class="dbus-property" generated="True" extra-ref="DefaultHostname"/>
|
||||
|
||||
<variablelist class="dbus-property" generated="True" extra-ref="HostnameSource"/>
|
||||
|
||||
@ -183,13 +183,15 @@ node /org/freedesktop/hostname1 {
|
||||
set this setting will be the empty string. Applications should then find a suitable fallback, such as the
|
||||
dynamic hostname.</para>
|
||||
|
||||
<para>The <varname>FallbackHostname</varname> property exposes the fallback hostname (configured at
|
||||
compilation time).</para>
|
||||
<para>The <varname>DefaultHostname</varname> property exposes the default hostname (configured through
|
||||
<citerefentry><refentrytitle>os-release</refentrytitle><manvolnum>5</manvolnum></citerefentry>, or a
|
||||
fallback set at compilation time).</para>
|
||||
|
||||
<para>The <varname>HostnameSource</varname> property exposes the origin of the currently configured
|
||||
hostname. One of <literal>static</literal> (set from <filename>/etc/hostname</filename>),
|
||||
<literal>transient</literal> (a non-permanent hostname from an external source),
|
||||
<literal>fallback</literal> (the compiled-in fallback value).</para>
|
||||
<literal>default</literal> (the value from <filename>os-release</filename> or the the compiled-in
|
||||
fallback).</para>
|
||||
|
||||
<para>The <varname>IconName</varname> property exposes the <emphasis>icon name</emphasis> following the
|
||||
XDG icon naming spec. If not set, information such as the chassis type (see below) is used to find a
|
||||
@ -332,8 +334,8 @@ node /org/freedesktop/hostname1 {
|
||||
<listitem><para>Limit the hostname to 63 chars, which is the length of a DNS label.</para></listitem>
|
||||
|
||||
<listitem><para>If after stripping special chars the empty string is the result, you can pass this
|
||||
as-is to <filename>systemd-hostnamed</filename> in which case it will automatically use
|
||||
<literal>&FALLBACK_HOSTNAME;</literal>.</para></listitem>
|
||||
as-is to <filename>systemd-hostnamed</filename> in which case it will automatically use a suitable
|
||||
fallback.</para></listitem>
|
||||
|
||||
<listitem><para>Uppercase charaacters should be replaced with their lowercase equivalents.
|
||||
</para></listitem>
|
||||
|
@ -345,7 +345,7 @@ static int context_update_kernel_hostname(
|
||||
if (!hn)
|
||||
return log_oom();
|
||||
|
||||
hns = HOSTNAME_FALLBACK;
|
||||
hns = HOSTNAME_DEFAULT;
|
||||
}
|
||||
|
||||
r = sethostname_idempotent(hn);
|
||||
@ -539,7 +539,7 @@ static int property_get_static_hostname(
|
||||
return sd_bus_message_append(reply, "s", c->data[PROP_STATIC_HOSTNAME]);
|
||||
}
|
||||
|
||||
static int property_get_fallback_hostname(
|
||||
static int property_get_default_hostname(
|
||||
sd_bus *bus,
|
||||
const char *path,
|
||||
const char *interface,
|
||||
@ -581,16 +581,16 @@ static int property_get_hostname_source(
|
||||
|
||||
else {
|
||||
/* If the hostname was not set by us, try to figure out where it came from. If we set
|
||||
* it to the fallback hostname, the file will tell us. We compare the string because
|
||||
* it to the default hostname, the file will tell us. We compare the string because
|
||||
* it is possible that the hostname was set by an older version that had a different
|
||||
* fallback, in the initramfs or before we reexecuted. */
|
||||
|
||||
r = read_one_line_file("/run/systemd/fallback-hostname", &fallback);
|
||||
r = read_one_line_file("/run/systemd/default-hostname", &fallback);
|
||||
if (r < 0 && r != -ENOENT)
|
||||
log_warning_errno(r, "Failed to read /run/systemd/fallback-hostname, ignoring: %m");
|
||||
log_warning_errno(r, "Failed to read /run/systemd/default-hostname, ignoring: %m");
|
||||
|
||||
if (streq_ptr(fallback, hostname))
|
||||
c->hostname_source = HOSTNAME_FALLBACK;
|
||||
c->hostname_source = HOSTNAME_DEFAULT;
|
||||
else
|
||||
c->hostname_source = HOSTNAME_TRANSIENT;
|
||||
}
|
||||
@ -988,7 +988,7 @@ static const sd_bus_vtable hostname_vtable[] = {
|
||||
SD_BUS_PROPERTY("Hostname", "s", property_get_hostname, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("StaticHostname", "s", property_get_static_hostname, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("PrettyHostname", "s", property_get_machine_info_field, offsetof(Context, data) + sizeof(char*) * PROP_PRETTY_HOSTNAME, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("FallbackHostname", "s", property_get_fallback_hostname, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("DefaultHostname", "s", property_get_default_hostname, 0, SD_BUS_VTABLE_PROPERTY_CONST),
|
||||
SD_BUS_PROPERTY("HostnameSource", "s", property_get_hostname_source, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("IconName", "s", property_get_icon_name, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
SD_BUS_PROPERTY("Chassis", "s", property_get_chassis, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||
|
@ -152,13 +152,13 @@ void hostname_update_source_hint(const char *hostname, HostnameSource source) {
|
||||
* notice if somebody sets the hostname directly (not going through hostnamed).
|
||||
*/
|
||||
|
||||
if (source == HOSTNAME_FALLBACK) {
|
||||
r = write_string_file("/run/systemd/fallback-hostname", hostname,
|
||||
if (source == HOSTNAME_DEFAULT) {
|
||||
r = write_string_file("/run/systemd/default-hostname", hostname,
|
||||
WRITE_STRING_FILE_CREATE | WRITE_STRING_FILE_ATOMIC);
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "Failed to create \"/run/systemd/fallback-hostname\": %m");
|
||||
log_warning_errno(r, "Failed to create \"/run/systemd/default-hostname\": %m");
|
||||
} else
|
||||
unlink_or_warn("/run/systemd/fallback-hostname");
|
||||
unlink_or_warn("/run/systemd/default-hostname");
|
||||
}
|
||||
|
||||
int hostname_setup(bool really) {
|
||||
@ -204,13 +204,13 @@ int hostname_setup(bool really) {
|
||||
}
|
||||
|
||||
if (enoent)
|
||||
log_info("No hostname configured, using fallback hostname.");
|
||||
log_info("No hostname configured, using default hostname.");
|
||||
|
||||
hn = b = get_default_hostname();
|
||||
if (!hn)
|
||||
return log_oom();
|
||||
|
||||
source = HOSTNAME_FALLBACK;
|
||||
source = HOSTNAME_DEFAULT;
|
||||
|
||||
}
|
||||
|
||||
@ -233,7 +233,7 @@ int hostname_setup(bool really) {
|
||||
static const char* const hostname_source_table[] = {
|
||||
[HOSTNAME_STATIC] = "static",
|
||||
[HOSTNAME_TRANSIENT] = "transient",
|
||||
[HOSTNAME_FALLBACK] = "fallback",
|
||||
[HOSTNAME_DEFAULT] = "default",
|
||||
};
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP(hostname_source, HostnameSource);
|
||||
|
@ -7,7 +7,7 @@
|
||||
typedef enum HostnameSource {
|
||||
HOSTNAME_STATIC, /* from /etc/hostname */
|
||||
HOSTNAME_TRANSIENT, /* a transient hostname set through systemd, hostnamed, the container manager, or otherwise */
|
||||
HOSTNAME_FALLBACK, /* the compiled-in fallback was used */
|
||||
HOSTNAME_DEFAULT, /* the os-release default or the compiled-in fallback were used */
|
||||
_HOSTNAME_INVALID = -EINVAL,
|
||||
} HostnameSource;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user