diff options
author | Lennart Poettering <lennart@poettering.net> | 2023-01-23 13:17:21 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2023-01-24 15:33:38 +0100 |
commit | 2b72626ee520d911337158b9d604db28534e8de8 (patch) | |
tree | 6ba8f594670a080e4fd95efc4df8816d1864d093 /src/hostname | |
parent | hostnamed: expose support end timestamp as property on the bus (diff) | |
download | systemd-2b72626ee520d911337158b9d604db28534e8de8.tar.xz systemd-2b72626ee520d911337158b9d604db28534e8de8.zip |
hostnamectl: show support and among output
Diffstat (limited to 'src/hostname')
-rw-r--r-- | src/hostname/hostnamectl.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c index c77e2e8fd9..4e30053392 100644 --- a/src/hostname/hostnamectl.c +++ b/src/hostname/hostnamectl.c @@ -47,6 +47,7 @@ typedef struct StatusInfo { const char *kernel_release; const char *os_pretty_name; const char *os_cpe_name; + usec_t os_support_end; const char *virtualization; const char *architecture; const char *home_url; @@ -76,6 +77,23 @@ static const char* chassis_string_to_glyph(const char *chassis) { return NULL; } +static const char *os_support_end_color(usec_t n, usec_t eol) { + usec_t left; + + /* If the end of support is over, color output in red. If only a month is left, color output in + * yellow. If more than a year is left, color green. In between just show in regular color. */ + + if (n >= eol) + return ANSI_HIGHLIGHT_RED; + left = eol - n; + if (left < USEC_PER_MONTH) + return ANSI_HIGHLIGHT_YELLOW; + if (left > USEC_PER_YEAR) + return ANSI_HIGHLIGHT_GREEN; + + return NULL; +} + static int print_status_info(StatusInfo *i) { _cleanup_(table_unrefp) Table *table = NULL; sd_id128_t mid = {}, bid = {}; @@ -198,6 +216,19 @@ static int print_status_info(StatusInfo *i) { return table_log_add_error(r); } + if (i->os_support_end != USEC_INFINITY) { + usec_t n = now(CLOCK_REALTIME); + + r = table_add_many(table, + TABLE_FIELD, "OS Support End", + TABLE_TIMESTAMP_DATE, i->os_support_end, + TABLE_FIELD, n < i->os_support_end ? "OS Support Remaining" : "OS Support Expired", + TABLE_TIMESPAN_DAY, n < i->os_support_end ? i->os_support_end - n : n - i->os_support_end, + TABLE_SET_COLOR, os_support_end_color(n, i->os_support_end)); + if (r < 0) + return table_log_add_error(r); + } + if (!isempty(i->kernel_name) && !isempty(i->kernel_release)) { const char *v; @@ -310,6 +341,7 @@ static int show_all_names(sd_bus *bus) { { "KernelRelease", "s", NULL, offsetof(StatusInfo, kernel_release) }, { "OperatingSystemPrettyName", "s", NULL, offsetof(StatusInfo, os_pretty_name) }, { "OperatingSystemCPEName", "s", NULL, offsetof(StatusInfo, os_cpe_name) }, + { "OperatingSystemSupportEnd", "t", NULL, offsetof(StatusInfo, os_support_end) }, { "HomeURL", "s", NULL, offsetof(StatusInfo, home_url) }, { "HardwareVendor", "s", NULL, offsetof(StatusInfo, hardware_vendor) }, { "HardwareModel", "s", NULL, offsetof(StatusInfo, hardware_model) }, |