From 2b5eff67f5dd91c31dddf3b8e2142bb4c30d3419 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 20 Jun 2023 15:26:19 +0200 Subject: [PATCH] hostnamectl: show age of firmware as time span, too This converts the date into a relative timespan from the current time on, and outputs it. It marks it yellow if older than two years, since old firmware is probably a security risk. We don't make it red, since we don't know though. --- src/hostname/hostnamectl.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c index 8d3cca5c621..b1cf19205bf 100644 --- a/src/hostname/hostnamectl.c +++ b/src/hostname/hostnamectl.c @@ -274,11 +274,22 @@ static int print_status_info(StatusInfo *i) { } if (timestamp_is_set(i->firmware_date)) { + usec_t n = now(CLOCK_REALTIME); + r = table_add_many(table, TABLE_FIELD, "Firmware Date", TABLE_TIMESTAMP_DATE, i->firmware_date); if (r < 0) return table_log_add_error(r); + + if (i->firmware_date < n) { + r = table_add_many(table, + TABLE_FIELD, "Firmware Age", + TABLE_TIMESPAN_DAY, n - i->firmware_date, + TABLE_SET_COLOR, n - i->firmware_date > USEC_PER_YEAR*2 ? ANSI_HIGHLIGHT_YELLOW : NULL); + if (r < 0) + return table_log_add_error(r); + } } r = table_print(table, NULL); -- 2.47.3