From: Lennart Poettering Date: Thu, 6 Mar 2025 11:02:10 +0000 (+0100) Subject: hostnamectl: show image info in hostnamectl X-Git-Tag: v258-rc1~1155^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bc60034f43ad47a9f5f60d572cf47f062d0dd21f;p=thirdparty%2Fsystemd.git hostnamectl: show image info in hostnamectl On image-based systems these properties are quite fundamental, hence show them in the hostnamed output. --- diff --git a/man/org.freedesktop.hostname1.xml b/man/org.freedesktop.hostname1.xml index ee34bf441c2..7de2e928296 100644 --- a/man/org.freedesktop.hostname1.xml +++ b/man/org.freedesktop.hostname1.xml @@ -86,6 +86,10 @@ node /org/freedesktop/hostname1 { @org.freedesktop.DBus.Property.EmitsChangedSignal("const") readonly s HomeURL = '...'; @org.freedesktop.DBus.Property.EmitsChangedSignal("const") + readonly s OperatingSystemImageID = '...'; + @org.freedesktop.DBus.Property.EmitsChangedSignal("const") + readonly s OperatingSystemImageVersion = '...'; + @org.freedesktop.DBus.Property.EmitsChangedSignal("const") readonly s HardwareVendor = '...'; @org.freedesktop.DBus.Property.EmitsChangedSignal("const") readonly s HardwareModel = '...'; @@ -168,6 +172,10 @@ node /org/freedesktop/hostname1 { + + + + @@ -293,6 +301,11 @@ node /org/freedesktop/hostname1 { information is known. It's an unsigned 64bit value, in µs since the UNIX epoch, UTC. If this information is not known carries the value 2^64-1, i.e. UINT64_MAX. + OperatingSystemImageID and OperatingSystemImageVersion expose + the OS image name and version if available, or contain empty strings otherwise. This mostly corresponds + to the IMAGE_ID= and IMAGE_VERSION= fields of the + os-release file. + HardwareVendor and HardwareModel expose information about the vendor of the hardware of the system. If no such information can be determined these properties are set to empty strings. @@ -460,7 +473,8 @@ node /org/freedesktop/hostname1 { FirmwareDate were added in version 253. MachineID, BootID and VSockCID were added in version 256. - ChassisAssetTag was added in version 258. + ChassisAssetTag, OperatingSystemImageID and + OperatingSystemImageVersion were added in version 258. diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c index c57d821fce2..88f068114ec 100644 --- a/src/hostname/hostnamectl.c +++ b/src/hostname/hostnamectl.c @@ -52,6 +52,8 @@ typedef struct StatusInfo { const char *os_pretty_name; const char *os_cpe_name; usec_t os_support_end; + const char *os_image_id; + const char *os_image_version; const char *virtualization; const char *architecture; const char *home_url; @@ -259,6 +261,22 @@ static int print_status_info(StatusInfo *i) { return table_log_add_error(r); } + if (!isempty(i->os_image_id)) { + r = table_add_many(table, + TABLE_FIELD, "OS Image", + TABLE_STRING, i->os_image_id); + if (r < 0) + return table_log_add_error(r); + } + + if (!isempty(i->os_image_version)) { + r = table_add_many(table, + TABLE_FIELD, "OS Image Version", + TABLE_STRING, i->os_image_version); + if (r < 0) + return table_log_add_error(r); + } + if (!isempty(i->kernel_name) && !isempty(i->kernel_release)) { const char *v; @@ -377,31 +395,33 @@ static int show_all_names(sd_bus *bus) { }; static const struct bus_properties_map hostname_map[] = { - { "Hostname", "s", NULL, offsetof(StatusInfo, hostname) }, - { "StaticHostname", "s", NULL, offsetof(StatusInfo, static_hostname) }, - { "PrettyHostname", "s", NULL, offsetof(StatusInfo, pretty_hostname) }, - { "IconName", "s", NULL, offsetof(StatusInfo, icon_name) }, - { "Chassis", "s", NULL, offsetof(StatusInfo, chassis) }, - { "ChassisAssetTag", "s", NULL, offsetof(StatusInfo, chassis_asset_tag)}, - { "Deployment", "s", NULL, offsetof(StatusInfo, deployment) }, - { "Location", "s", NULL, offsetof(StatusInfo, location) }, - { "KernelName", "s", NULL, offsetof(StatusInfo, kernel_name) }, - { "KernelRelease", "s", NULL, offsetof(StatusInfo, kernel_release) }, - { "OperatingSystemPrettyName", "s", NULL, offsetof(StatusInfo, os_pretty_name) }, - { "OperatingSystemCPEName", "s", NULL, offsetof(StatusInfo, os_cpe_name) }, - { "OperatingSystemSupportEnd", "t", NULL, offsetof(StatusInfo, os_support_end) }, - { "HomeURL", "s", NULL, offsetof(StatusInfo, home_url) }, - { "HardwareVendor", "s", NULL, offsetof(StatusInfo, hardware_vendor) }, - { "HardwareModel", "s", NULL, offsetof(StatusInfo, hardware_model) }, - { "FirmwareVersion", "s", NULL, offsetof(StatusInfo, firmware_version) }, - { "FirmwareDate", "t", NULL, offsetof(StatusInfo, firmware_date) }, - { "MachineID", "ay", bus_map_id128, offsetof(StatusInfo, machine_id) }, - { "BootID", "ay", bus_map_id128, offsetof(StatusInfo, boot_id) }, - { "VSockCID", "u", NULL, offsetof(StatusInfo, vsock_cid) }, + { "Hostname", "s", NULL, offsetof(StatusInfo, hostname) }, + { "StaticHostname", "s", NULL, offsetof(StatusInfo, static_hostname) }, + { "PrettyHostname", "s", NULL, offsetof(StatusInfo, pretty_hostname) }, + { "IconName", "s", NULL, offsetof(StatusInfo, icon_name) }, + { "Chassis", "s", NULL, offsetof(StatusInfo, chassis) }, + { "ChassisAssetTag", "s", NULL, offsetof(StatusInfo, chassis_asset_tag)}, + { "Deployment", "s", NULL, offsetof(StatusInfo, deployment) }, + { "Location", "s", NULL, offsetof(StatusInfo, location) }, + { "KernelName", "s", NULL, offsetof(StatusInfo, kernel_name) }, + { "KernelRelease", "s", NULL, offsetof(StatusInfo, kernel_release) }, + { "OperatingSystemPrettyName", "s", NULL, offsetof(StatusInfo, os_pretty_name) }, + { "OperatingSystemCPEName", "s", NULL, offsetof(StatusInfo, os_cpe_name) }, + { "OperatingSystemSupportEnd", "t", NULL, offsetof(StatusInfo, os_support_end) }, + { "OperatingSystemImageID", "s", NULL, offsetof(StatusInfo, os_image_id) }, + { "OperatingSystemImageVersion", "s", NULL, offsetof(StatusInfo, os_image_version) }, + { "HomeURL", "s", NULL, offsetof(StatusInfo, home_url) }, + { "HardwareVendor", "s", NULL, offsetof(StatusInfo, hardware_vendor) }, + { "HardwareModel", "s", NULL, offsetof(StatusInfo, hardware_model) }, + { "FirmwareVersion", "s", NULL, offsetof(StatusInfo, firmware_version) }, + { "FirmwareDate", "t", NULL, offsetof(StatusInfo, firmware_date) }, + { "MachineID", "ay", bus_map_id128, offsetof(StatusInfo, machine_id) }, + { "BootID", "ay", bus_map_id128, offsetof(StatusInfo, boot_id) }, + { "VSockCID", "u", NULL, offsetof(StatusInfo, vsock_cid) }, {} }, manager_map[] = { - { "Virtualization", "s", NULL, offsetof(StatusInfo, virtualization) }, - { "Architecture", "s", NULL, offsetof(StatusInfo, architecture) }, + { "Virtualization", "s", NULL, offsetof(StatusInfo, virtualization) }, + { "Architecture", "s", NULL, offsetof(StatusInfo, architecture) }, {} }; diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index ec30f774e83..110f0a7400c 100644 --- a/src/hostname/hostnamed.c +++ b/src/hostname/hostnamed.c @@ -67,6 +67,8 @@ typedef enum { PROP_OS_CPE_NAME, PROP_OS_HOME_URL, PROP_OS_SUPPORT_END, + PROP_OS_IMAGE_ID, + PROP_OS_IMAGE_VERSION, _PROP_MAX, _PROP_INVALID = -EINVAL, } HostProperty; @@ -181,14 +183,18 @@ static void context_read_os_release(Context *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_SUPPORT_END)); + (UINT64_C(1) << PROP_OS_SUPPORT_END) | + (UINT64_C(1) << PROP_OS_IMAGE_ID) | + (UINT64_C(1) << PROP_OS_IMAGE_VERSION)); 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], - "SUPPORT_END", &c->data[PROP_OS_SUPPORT_END]); + "PRETTY_NAME", &os_pretty_name, + "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], + "IMAGE_ID", &c->data[PROP_OS_IMAGE_ID], + "IMAGE_VERSION", &c->data[PROP_OS_IMAGE_VERSION]); if (r < 0 && r != -ENOENT) log_warning_errno(r, "Failed to read os-release file, ignoring: %m"); @@ -1571,6 +1577,8 @@ static int build_describe_response(Context *c, bool privileged, sd_json_variant SD_JSON_BUILD_PAIR_STRING("OperatingSystemHomeURL", c->data[PROP_OS_HOME_URL]), JSON_BUILD_PAIR_FINITE_USEC("OperatingSystemSupportEnd", eol), SD_JSON_BUILD_PAIR("OperatingSystemReleaseData", JSON_BUILD_STRV_ENV_PAIR(os_release_pairs)), + SD_JSON_BUILD_PAIR_STRING("OperatingSystemImageID", c->data[PROP_OS_IMAGE_ID]), + SD_JSON_BUILD_PAIR_STRING("OperatingSystemImageVersion", c->data[PROP_OS_IMAGE_VERSION]), SD_JSON_BUILD_PAIR("MachineInformationData", JSON_BUILD_STRV_ENV_PAIR(machine_info_pairs)), SD_JSON_BUILD_PAIR_STRING("HardwareVendor", vendor ?: c->data[PROP_HARDWARE_VENDOR]), SD_JSON_BUILD_PAIR_STRING("HardwareModel", model ?: c->data[PROP_HARDWARE_MODEL]), @@ -1628,20 +1636,22 @@ static const sd_bus_vtable hostname_vtable[] = { SD_BUS_VTABLE_START(0), 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("PrettyHostname", "s", property_get_machine_info_field, offsetof(Context, data[PROP_PRETTY_HOSTNAME]), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), 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), - SD_BUS_PROPERTY("Deployment", "s", property_get_machine_info_field, offsetof(Context, data) + sizeof(char*) * PROP_DEPLOYMENT, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), - SD_BUS_PROPERTY("Location", "s", property_get_machine_info_field, offsetof(Context, data) + sizeof(char*) * PROP_LOCATION, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), + SD_BUS_PROPERTY("Deployment", "s", property_get_machine_info_field, offsetof(Context, data[PROP_DEPLOYMENT]), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), + SD_BUS_PROPERTY("Location", "s", property_get_machine_info_field, offsetof(Context, data[PROP_LOCATION]), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE), SD_BUS_PROPERTY("KernelName", "s", property_get_uname_field, offsetof(struct utsname, sysname), SD_BUS_VTABLE_ABSOLUTE_OFFSET|SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("KernelRelease", "s", property_get_uname_field, offsetof(struct utsname, release), SD_BUS_VTABLE_ABSOLUTE_OFFSET|SD_BUS_VTABLE_PROPERTY_CONST), 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("OperatingSystemPrettyName", "s", property_get_os_release_field, offsetof(Context, data[PROP_OS_PRETTY_NAME]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("OperatingSystemCPEName", "s", property_get_os_release_field, offsetof(Context, data[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("HomeURL", "s", property_get_os_release_field, offsetof(Context, data[PROP_OS_HOME_URL]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("OperatingSystemImageID", "s", property_get_os_release_field, offsetof(Context, data[PROP_OS_IMAGE_ID]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("OperatingSystemImageVersion", "s", property_get_os_release_field, offsetof(Context, data[PROP_OS_IMAGE_VERSION]), 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), SD_BUS_PROPERTY("FirmwareVersion", "s", property_get_firmware_version, 0, SD_BUS_VTABLE_PROPERTY_CONST),