const char *hardware_model;
const char *firmware_version;
usec_t firmware_date;
+ sd_id128_t machine_id;
+ sd_id128_t boot_id;
} StatusInfo;
static const char* chassis_string_to_glyph(const char *chassis) {
static int print_status_info(StatusInfo *i) {
_cleanup_(table_unrefp) Table *table = NULL;
- sd_id128_t mid = {}, bid = {};
TableCell *cell;
int r;
return table_log_add_error(r);
}
- r = sd_id128_get_machine(&mid);
- if (r >= 0) {
+ if (!sd_id128_is_null(i->machine_id)) {
r = table_add_many(table,
TABLE_FIELD, "Machine ID",
- TABLE_ID128, mid);
+ TABLE_ID128, i->machine_id);
if (r < 0)
return table_log_add_error(r);
}
- r = sd_id128_get_boot(&bid);
- if (r >= 0) {
+ if (!sd_id128_is_null(i->boot_id)) {
r = table_add_many(table,
TABLE_FIELD, "Boot ID",
- TABLE_ID128, bid);
+ TABLE_ID128, i->boot_id);
if (r < 0)
return table_log_add_error(r);
}
StatusInfo info = {};
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) },
- { "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) },
+ { "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) },
+ { "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) },
{}
- };
-
- static const struct bus_properties_map manager_map[] = {
- { "Virtualization", "s", NULL, offsetof(StatusInfo, virtualization) },
- { "Architecture", "s", NULL, offsetof(StatusInfo, architecture) },
+ }, manager_map[] = {
+ { "Virtualization", "s", NULL, offsetof(StatusInfo, virtualization) },
+ { "Architecture", "s", NULL, offsetof(StatusInfo, architecture) },
{}
};
if (r < 0)
return log_error_errno(r, "Failed to query system properties: %s", bus_error_message(&error, r));
+ /* For older version of hostnamed. */
+ if (!arg_host) {
+ if (sd_id128_is_null(info.machine_id))
+ (void) sd_id128_get_machine(&info.machine_id);
+ if (sd_id128_is_null(info.boot_id))
+ (void) sd_id128_get_boot(&info.boot_id);
+ }
+
return print_status_info(&info);
}
return sd_bus_message_append(reply, "s", (char*) &u + PTR_TO_SIZE(userdata));
}
+static int property_get_machine_id(
+ sd_bus *bus,
+ const char *path,
+ const char *interface,
+ const char *property,
+ sd_bus_message *reply,
+ void *userdata,
+ sd_bus_error *error) {
+
+ sd_id128_t id;
+ int r;
+
+ r = sd_id128_get_machine(&id);
+ if (r < 0)
+ return r;
+
+ return bus_property_get_id128(bus, path, interface, property, reply, &id, error);
+}
+
+static int property_get_boot_id(
+ sd_bus *bus,
+ const char *path,
+ const char *interface,
+ const char *property,
+ sd_bus_message *reply,
+ void *userdata,
+ sd_bus_error *error) {
+
+ sd_id128_t id;
+ int r;
+
+ r = sd_id128_get_boot(&id);
+ if (r < 0)
+ return r;
+
+ return bus_property_get_id128(bus, path, interface, property, reply, &id, error);
+}
+
static int method_set_hostname(sd_bus_message *m, void *userdata, sd_bus_error *error) {
Context *c = ASSERT_PTR(userdata);
const char *name;
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;
+ sd_id128_t machine_id, boot_id, product_uuid = SD_ID128_NULL;
Context *c = ASSERT_PTR(userdata);
bool privileged;
struct utsname u;
if (c->data[PROP_OS_SUPPORT_END])
(void) os_release_support_ended(c->data[PROP_OS_SUPPORT_END], /* quiet= */ false, &eol);
+ r = sd_id128_get_machine(&machine_id);
+ if (r < 0)
+ return log_error_errno(r, "Failed to get machine ID: %m");
+
+ r = sd_id128_get_boot(&boot_id);
+ if (r < 0)
+ return log_error_errno(r, "Failed to get boot ID: %m");
+
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])),
JSON_BUILD_PAIR("FirmwareVersion", JSON_BUILD_STRING(firmware_version)),
JSON_BUILD_PAIR("FirmwareVendor", JSON_BUILD_STRING(firmware_vendor)),
JSON_BUILD_PAIR_FINITE_USEC("FirmwareDate", firmware_date),
+ JSON_BUILD_PAIR_ID128("MachineID", machine_id),
+ JSON_BUILD_PAIR_ID128("BootID", boot_id),
JSON_BUILD_PAIR_CONDITION(!sd_id128_is_null(product_uuid), "ProductUUID", JSON_BUILD_ID128(product_uuid)),
JSON_BUILD_PAIR_CONDITION(sd_id128_is_null(product_uuid), "ProductUUID", JSON_BUILD_NULL)));
SD_BUS_PROPERTY("FirmwareVersion", "s", property_get_firmware_version, 0, SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("FirmwareVendor", "s", property_get_firmware_vendor, 0, SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("FirmwareDate", "t", property_get_firmware_date, 0, SD_BUS_VTABLE_PROPERTY_CONST),
+ SD_BUS_PROPERTY("MachineID", "ay", property_get_machine_id, 0, SD_BUS_VTABLE_PROPERTY_CONST),
+ SD_BUS_PROPERTY("BootID", "ay", property_get_boot_id, 0, SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_METHOD_WITH_ARGS("SetHostname",
SD_BUS_ARGS("s", hostname, "b", interactive),