From b563d5ce6f365955722446d67e58398b130f8052 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 23 Jan 2023 13:16:52 +0100 Subject: [PATCH] hostnamed: expose support end timestamp as property on the bus --- man/org.freedesktop.hostname1.xml | 6 +++++ src/hostname/hostnamed.c | 38 +++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/man/org.freedesktop.hostname1.xml b/man/org.freedesktop.hostname1.xml index be36d8fc7e3..7cad9a76247 100644 --- a/man/org.freedesktop.hostname1.xml +++ b/man/org.freedesktop.hostname1.xml @@ -82,6 +82,8 @@ node /org/freedesktop/hostname1 { @org.freedesktop.DBus.Property.EmitsChangedSignal("const") readonly s OperatingSystemCPEName = '...'; @org.freedesktop.DBus.Property.EmitsChangedSignal("const") + readonly t OperatingSystemSupportEnd = ...; + @org.freedesktop.DBus.Property.EmitsChangedSignal("const") readonly s HomeURL = '...'; @org.freedesktop.DBus.Property.EmitsChangedSignal("const") readonly s HardwareVendor = '...'; @@ -102,6 +104,8 @@ node /org/freedesktop/hostname1 { + + @@ -166,6 +170,8 @@ node /org/freedesktop/hostname1 { + + diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index a17ecd2b9b0..36ab0148b9b 100644 --- a/src/hostname/hostnamed.c +++ b/src/hostname/hostnamed.c @@ -59,6 +59,7 @@ typedef enum { PROP_OS_PRETTY_NAME, PROP_OS_CPE_NAME, PROP_OS_HOME_URL, + PROP_OS_SUPPORT_END, _PROP_MAX, _PROP_INVALID = -EINVAL, } HostProperty; @@ -160,13 +161,15 @@ static void context_read_os_release(Context *c) { context_reset(c, (UINT64_C(1) << PROP_OS_PRETTY_NAME) | (UINT64_C(1) << PROP_OS_CPE_NAME) | - (UINT64_C(1) << PROP_OS_HOME_URL)); + (UINT64_C(1) << PROP_OS_HOME_URL) | + (UINT64_C(1) << PROP_OS_SUPPORT_END)); r = parse_os_release(NULL, "PRETTY_NAME", &os_pretty_name, - "NAME", &os_name, - "CPE_NAME", &c->data[PROP_OS_CPE_NAME], - "HOME_URL", &c->data[PROP_OS_HOME_URL]); + "NAME", &os_name, + "CPE_NAME", &c->data[PROP_OS_CPE_NAME], + "HOME_URL", &c->data[PROP_OS_HOME_URL], + "SUPPORT_END", &c->data[PROP_OS_SUPPORT_END]); if (r < 0 && r != -ENOENT) log_warning_errno(r, "Failed to read os-release file, ignoring: %m"); @@ -886,6 +889,26 @@ static int property_get_os_release_field( return sd_bus_message_append(reply, "s", *(char**) userdata); } +static int property_get_os_support_end( + sd_bus *bus, + const char *path, + const char *interface, + const char *property, + sd_bus_message *reply, + void *userdata, + sd_bus_error *error) { + + Context *c = userdata; + usec_t eol = USEC_INFINITY; + + context_read_os_release(c); + + if (c->data[PROP_OS_SUPPORT_END]) + (void) os_release_support_ended(c->data[PROP_OS_SUPPORT_END], /* quiet= */ false, &eol); + + return sd_bus_message_append(reply, "t", eol); +} + static int property_get_icon_name( sd_bus *bus, const char *path, @@ -1251,7 +1274,7 @@ static int method_describe(sd_bus_message *m, void *userdata, sd_bus_error *erro _cleanup_free_ char *hn = NULL, *dhn = NULL, *in = NULL, *text = NULL, *chassis = NULL, *vendor = NULL, *model = NULL, *serial = NULL, *firmware_version = NULL, *firmware_vendor = NULL; - usec_t firmware_date = USEC_INFINITY; + usec_t firmware_date = USEC_INFINITY, eol = USEC_INFINITY; _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; _cleanup_(json_variant_unrefp) JsonVariant *v = NULL; sd_id128_t product_uuid = SD_ID128_NULL; @@ -1318,6 +1341,9 @@ static int method_describe(sd_bus_message *m, void *userdata, sd_bus_error *erro (void) get_firmware_vendor(&firmware_vendor); (void) get_firmware_date(&firmware_date); + if (c->data[PROP_OS_SUPPORT_END]) + (void) os_release_support_ended(c->data[PROP_OS_SUPPORT_END], /* quiet= */ false, &eol); + r = json_build(&v, JSON_BUILD_OBJECT( JSON_BUILD_PAIR("Hostname", JSON_BUILD_STRING(hn)), JSON_BUILD_PAIR("StaticHostname", JSON_BUILD_STRING(c->data[PROP_STATIC_HOSTNAME])), @@ -1334,6 +1360,7 @@ static int method_describe(sd_bus_message *m, void *userdata, sd_bus_error *erro JSON_BUILD_PAIR("OperatingSystemPrettyName", JSON_BUILD_STRING(c->data[PROP_OS_PRETTY_NAME])), JSON_BUILD_PAIR("OperatingSystemCPEName", JSON_BUILD_STRING(c->data[PROP_OS_CPE_NAME])), JSON_BUILD_PAIR("OperatingSystemHomeURL", JSON_BUILD_STRING(c->data[PROP_OS_HOME_URL])), + JSON_BUILD_PAIR_FINITE_USEC("OperatingSystemSupportEnd", eol), JSON_BUILD_PAIR("HardwareVendor", JSON_BUILD_STRING(vendor ?: c->data[PROP_HARDWARE_VENDOR])), JSON_BUILD_PAIR("HardwareModel", JSON_BUILD_STRING(model ?: c->data[PROP_HARDWARE_MODEL])), JSON_BUILD_PAIR("HardwareSerial", JSON_BUILD_STRING(serial)), @@ -1377,6 +1404,7 @@ static const sd_bus_vtable hostname_vtable[] = { SD_BUS_PROPERTY("KernelVersion", "s", property_get_uname_field, offsetof(struct utsname, version), SD_BUS_VTABLE_ABSOLUTE_OFFSET|SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("OperatingSystemPrettyName", "s", property_get_os_release_field, offsetof(Context, data) + sizeof(char*) * PROP_OS_PRETTY_NAME, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("OperatingSystemCPEName", "s", property_get_os_release_field, offsetof(Context, data) + sizeof(char*) * PROP_OS_CPE_NAME, SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("OperatingSystemSupportEnd", "t", property_get_os_support_end, 0, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("HomeURL", "s", property_get_os_release_field, offsetof(Context, data) + sizeof(char*) * PROP_OS_HOME_URL, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("HardwareVendor", "s", property_get_hardware_vendor, 0, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("HardwareModel", "s", property_get_hardware_model, 0, SD_BUS_VTABLE_PROPERTY_CONST),