os-util: optionally, return EOL time in os_release_support_ended()

This commit is contained in:
Lennart Poettering 2023-01-23 13:16:12 +01:00
parent a9bd4b4ed9
commit 6bfe9b3b8d
5 changed files with 12 additions and 10 deletions

View File

@ -336,7 +336,7 @@ int load_extension_release_pairs(const char *root, const char *extension, bool r
return load_env_file_pairs(f, p, ret);
}
int os_release_support_ended(const char *support_end, bool quiet) {
int os_release_support_ended(const char *support_end, bool quiet, usec_t *ret_eol) {
_cleanup_free_ char *_support_end_alloc = NULL;
int r;
@ -367,8 +367,10 @@ int os_release_support_ended(const char *support_end, bool quiet) {
return log_full_errno(quiet ? LOG_DEBUG : LOG_WARNING, SYNTHETIC_ERRNO(EINVAL),
"Failed to convert SUPPORT_END= in os-release file, ignoring: %m");
usec_t ts = now(CLOCK_REALTIME);
return DIV_ROUND_UP(ts, USEC_PER_SEC) > (usec_t) eol;
if (ret_eol)
*ret_eol = eol * USEC_PER_SEC;
return DIV_ROUND_UP(now(CLOCK_REALTIME), USEC_PER_SEC) > (usec_t) eol;
}
const char *os_release_pretty_name(const char *pretty_name, const char *name) {

View File

@ -32,6 +32,6 @@ int load_extension_release_pairs(const char *root, const char *extension, bool r
int load_os_release_pairs(const char *root, char ***ret);
int load_os_release_pairs_with_prefix(const char *root, const char *prefix, char ***ret);
int os_release_support_ended(const char *support_end, bool quiet);
int os_release_support_ended(const char *support_end, bool quiet, usec_t *ret_eol);
const char *os_release_pretty_name(const char *pretty_name, const char *name);

View File

@ -1385,7 +1385,7 @@ static int os_release_status(void) {
label);
}
if (support_end && os_release_support_ended(support_end, false) > 0)
if (support_end && os_release_support_ended(support_end, /* quiet */ false, NULL) > 0)
/* pretty_name may include the version already, so we'll print the version only if we
* have it and we're not using pretty_name. */
status_printf(ANSI_HIGHLIGHT_RED " !! " ANSI_NORMAL, 0,

View File

@ -4547,7 +4547,7 @@ char* manager_taint_string(const Manager *m) {
if (clock_is_localtime(NULL) > 0)
stage[n++] = "local-hwclock";
if (os_release_support_ended(NULL, true) > 0)
if (os_release_support_ended(NULL, /* quiet= */ true, NULL) > 0)
stage[n++] = "support-ended";
_cleanup_free_ char *destination = NULL;

View File

@ -75,11 +75,11 @@ TEST(load_os_release_pairs) {
TEST(os_release_support_ended) {
int r;
assert_se(os_release_support_ended("1999-01-01", false) == true);
assert_se(os_release_support_ended("2037-12-31", false) == false);
assert_se(os_release_support_ended("-1-1-1", true) == -EINVAL);
assert_se(os_release_support_ended("1999-01-01", false, NULL) == true);
assert_se(os_release_support_ended("2037-12-31", false, NULL) == false);
assert_se(os_release_support_ended("-1-1-1", true, NULL) == -EINVAL);
r = os_release_support_ended(NULL, false);
r = os_release_support_ended(NULL, false, NULL);
if (r < 0)
log_info_errno(r, "Failed to check host: %m");
else