]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
hostnamed: expose the fallback-hostname setting as a const dbus property
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 4 Dec 2020 14:16:54 +0000 (15:16 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 16 Dec 2020 09:54:57 +0000 (10:54 +0100)
Various users want to know what the fallback hostname is. Since it was made
configurable in 8146c32b9264a6915d467a5cab1a24311fbede7e, we didn't expose this
nicely.

man/org.freedesktop.hostname1.xml
src/hostname/hostnamed.c

index c715bad593dc7379f52112cd4c757d2eae187e37..8e5c37345d6b8b62a605bc92a1691a207f0d278a 100644 (file)
@@ -62,6 +62,8 @@ node /org/freedesktop/hostname1 {
       readonly s Hostname = '...';
       readonly s StaticHostname = '...';
       readonly s PrettyHostname = '...';
+      @org.freedesktop.DBus.Property.EmitsChangedSignal("const")
+      readonly s FallbackHostname = '...';
       readonly s IconName = '...';
       readonly s Chassis = '...';
       readonly s Deployment = '...';
@@ -113,6 +115,8 @@ 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="IconName"/>
 
     <variablelist class="dbus-property" generated="True" extra-ref="Chassis"/>
@@ -164,6 +168,9 @@ 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>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
     suitable fallback icon name (i.e. <literal>computer-laptop</literal>
index a0dc25c8347b174e5115a0643ce7b6ca5494d8fa..bec1fde5a556aa5e34a0045db9ab13f2fe482d19 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "alloc-util.h"
 #include "bus-common-errors.h"
+#include "bus-get-properties.h"
 #include "bus-log-control-api.h"
 #include "bus-polkit.h"
 #include "def.h"
@@ -461,6 +462,8 @@ static int property_get_static_hostname(
         return sd_bus_message_append(reply, "s", c->data[PROP_STATIC_HOSTNAME]);
 }
 
+static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_fallback_hostname, "s", FALLBACK_HOSTNAME);
+
 static int property_get_machine_info_field(
                 sd_bus *bus,
                 const char *path,
@@ -850,6 +853,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("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),
         SD_BUS_PROPERTY("Deployment", "s", property_get_machine_info_field, offsetof(Context, data) + sizeof(char*) * PROP_DEPLOYMENT, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),