]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
hostnamectl: show age of firmware as time span, too
authorLennart Poettering <lennart@poettering.net>
Tue, 20 Jun 2023 13:26:19 +0000 (15:26 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 20 Jun 2023 16:40:30 +0000 (18:40 +0200)
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

index 8d3cca5c6215c495dee77f765140f48660ab8dc9..b1cf19205bf299c71798ff1f8b882f196c5f2c4c 100644 (file)
@@ -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);