From: Lennart Poettering Date: Fri, 1 Mar 2024 13:43:20 +0000 (+0100) Subject: hostnamectl: display product uuid + hardware serial in regular status output X-Git-Tag: v256-rc1~672^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=75c7df05fbc8b6b4ee4ed25165b0622175c56e77;p=thirdparty%2Fsystemd.git hostnamectl: display product uuid + hardware serial in regular status output hostnamed provides this, hence hostnamectl should show it --- diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c index 4abcf40c263..a70c9572910 100644 --- a/src/hostname/hostnamectl.c +++ b/src/hostname/hostnamectl.c @@ -59,6 +59,8 @@ typedef struct StatusInfo { usec_t firmware_date; sd_id128_t machine_id; sd_id128_t boot_id; + const char *hardware_serial; + sd_id128_t product_uuid; uint32_t vsock_cid; } StatusInfo; @@ -193,6 +195,14 @@ static int print_status_info(StatusInfo *i) { return table_log_add_error(r); } + if (!sd_id128_is_null(i->product_uuid)) { + r = table_add_many(table, + TABLE_FIELD, "Product UUID", + TABLE_UUID, i->product_uuid); + if (r < 0) + return table_log_add_error(r); + } + if (i->vsock_cid != VMADDR_CID_ANY) { r = table_add_many(table, TABLE_FIELD, "AF_VSOCK CID", @@ -274,6 +284,14 @@ static int print_status_info(StatusInfo *i) { return table_log_add_error(r); } + if (!isempty(i->hardware_serial)) { + r = table_add_many(table, + TABLE_FIELD, "Hardware Serial", + TABLE_STRING, i->hardware_serial); + if (r < 0) + return table_log_add_error(r); + } + if (!isempty(i->firmware_version)) { r = table_add_many(table, TABLE_FIELD, "Firmware Version", @@ -400,6 +418,48 @@ static int show_all_names(sd_bus *bus) { if (r < 0) return log_error_errno(r, "Failed to query system properties: %s", bus_error_message(&error, r)); + _cleanup_(sd_bus_message_unrefp) sd_bus_message *product_uuid_reply = NULL; + r = bus_call_method(bus, + bus_hostname, + "GetProductUUID", + &error, + &product_uuid_reply, + "b", + false); + if (r < 0) { + log_full_errno(sd_bus_error_has_names( + &error, + BUS_ERROR_NO_PRODUCT_UUID, + SD_BUS_ERROR_INTERACTIVE_AUTHORIZATION_REQUIRED, + SD_BUS_ERROR_UNKNOWN_METHOD) ? LOG_DEBUG : LOG_WARNING, + r, "Failed to query product UUID, ignoring: %s", bus_error_message(&error, r)); + sd_bus_error_free(&error); + } else { + r = bus_message_read_id128(product_uuid_reply, &info.product_uuid); + if (r < 0) + return bus_log_parse_error(r); + } + + _cleanup_(sd_bus_message_unrefp) sd_bus_message *hardware_serial_reply = NULL; + r = bus_call_method(bus, + bus_hostname, + "GetHardwareSerial", + &error, + &hardware_serial_reply, + NULL); + if (r < 0) + log_full_errno(sd_bus_error_has_names( + &error, + BUS_ERROR_NO_HARDWARE_SERIAL, + SD_BUS_ERROR_INTERACTIVE_AUTHORIZATION_REQUIRED, + SD_BUS_ERROR_UNKNOWN_METHOD) ? LOG_DEBUG : LOG_WARNING, + r, "Failed to query hardware serial, ignoring: %s", bus_error_message(&error, r)); + else { + r = sd_bus_message_read_basic(hardware_serial_reply, 's', &info.hardware_serial); + if (r < 0) + return bus_log_parse_error(r); + } + /* For older version of hostnamed. */ if (!arg_host) { if (sd_id128_is_null(info.machine_id))