mirror of
https://github.com/systemd/systemd.git
synced 2024-11-27 04:03:36 +08:00
hostnamed: expose support end timestamp as property on the bus
This commit is contained in:
parent
6bfe9b3b8d
commit
b563d5ce6f
@ -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 {
|
||||
|
||||
<!--method GetHardwareSerial is not documented!-->
|
||||
|
||||
<!--property OperatingSystemSupportEnd is not documented!-->
|
||||
|
||||
<!--property HardwareVendor is not documented!-->
|
||||
|
||||
<!--property HardwareModel is not documented!-->
|
||||
@ -166,6 +170,8 @@ node /org/freedesktop/hostname1 {
|
||||
|
||||
<variablelist class="dbus-property" generated="True" extra-ref="OperatingSystemCPEName"/>
|
||||
|
||||
<variablelist class="dbus-property" generated="True" extra-ref="OperatingSystemSupportEnd"/>
|
||||
|
||||
<variablelist class="dbus-property" generated="True" extra-ref="HomeURL"/>
|
||||
|
||||
<variablelist class="dbus-property" generated="True" extra-ref="HardwareVendor"/>
|
||||
|
@ -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]);
|
||||
"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),
|
||||
|
Loading…
Reference in New Issue
Block a user