From: Lennart Poettering Date: Tue, 20 Jun 2023 13:26:19 +0000 (+0200) Subject: hostnamectl: show age of firmware as time span, too X-Git-Tag: v254-rc1~162 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b5eff67f5dd91c31dddf3b8e2142bb4c30d3419;p=thirdparty%2Fsystemd.git 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. --- 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);