From ce6b138c7576df55ede15f5d8b02a1766449bd1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 4 Dec 2020 15:16:54 +0100 Subject: [PATCH] hostnamed: expose the fallback-hostname setting as a const dbus property 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 | 7 +++++++ src/hostname/hostnamed.c | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/man/org.freedesktop.hostname1.xml b/man/org.freedesktop.hostname1.xml index c715bad593..8e5c37345d 100644 --- a/man/org.freedesktop.hostname1.xml +++ b/man/org.freedesktop.hostname1.xml @@ -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 { + + @@ -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. + The FallbackHostname property exposes the fallback hostname (configured at + compilation time). + The IconName property exposes the icon name 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. computer-laptop diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index a0dc25c834..bec1fde5a5 100644 --- a/src/hostname/hostnamed.c +++ b/src/hostname/hostnamed.c @@ -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),