From: Yu Watanabe Date: Sat, 2 Dec 2023 10:14:35 +0000 (+0900) Subject: hostnamectl: do not show local machine ID and boot ID when requested to show informat... X-Git-Tag: v256-rc1~1579^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=01e554e2e71859220e86a14212420720e05bccbf;p=thirdparty%2Fsystemd.git hostnamectl: do not show local machine ID and boot ID when requested to show information about remote host Prompted by #30293. --- diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c index b1cf19205bf..75226e3a00b 100644 --- a/src/hostname/hostnamectl.c +++ b/src/hostname/hostnamectl.c @@ -56,6 +56,8 @@ typedef struct StatusInfo { 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) { @@ -97,7 +99,6 @@ static const char *os_support_end_color(usec_t n, usec_t eol) { static int print_status_info(StatusInfo *i) { _cleanup_(table_unrefp) Table *table = NULL; - sd_id128_t mid = {}, bid = {}; TableCell *cell; int r; @@ -174,20 +175,18 @@ static int print_status_info(StatusInfo *i) { 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); } @@ -388,6 +387,13 @@ 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)); + 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); }