Merge pull request #26158 from poettering/hostnamed-end-of-support
hostnamed/hostnamectl: support os-release END_OF_SUPPORT= field
This commit is contained in:
+20
-9
@@ -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;
|
||||
|
||||
@@ -346,27 +346,38 @@ int os_release_support_ended(const char *support_end, bool quiet) {
|
||||
|
||||
r = parse_os_release(NULL,
|
||||
"SUPPORT_END", &_support_end_alloc);
|
||||
if (r < 0)
|
||||
return log_full_errno((r == -ENOENT || quiet) ? LOG_DEBUG : LOG_WARNING, r,
|
||||
if (r < 0 && r != -ENOENT)
|
||||
return log_full_errno(quiet ? LOG_DEBUG : LOG_WARNING, r,
|
||||
"Failed to read os-release file, ignoring: %m");
|
||||
if (!_support_end_alloc)
|
||||
return false; /* no end date defined */
|
||||
|
||||
support_end = _support_end_alloc;
|
||||
}
|
||||
|
||||
struct tm tm = {};
|
||||
if (isempty(support_end)) /* An empty string is a explicit way to say "no EOL exists" */
|
||||
return false; /* no end date defined */
|
||||
|
||||
struct tm tm = {};
|
||||
const char *k = strptime(support_end, "%Y-%m-%d", &tm);
|
||||
if (!k || *k)
|
||||
return log_full_errno(quiet ? LOG_DEBUG : LOG_WARNING, SYNTHETIC_ERRNO(EINVAL),
|
||||
"Failed to parse SUPPORT_END= in os-release file, ignoring: %m");
|
||||
|
||||
time_t eol = mktime(&tm);
|
||||
time_t eol = timegm(&tm);
|
||||
if (eol == (time_t) -1)
|
||||
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) {
|
||||
/* Distills a "pretty" name to show from os-release data. First argument is supposed to be the
|
||||
* PRETTY_NAME= field, the second one the NAME= field. This function is trivial, of course, and
|
||||
* exists mostly to ensure we use the same logic wherever possible. */
|
||||
|
||||
return empty_to_null(pretty_name) ?:
|
||||
empty_to_null(name) ?: "Linux";
|
||||
}
|
||||
|
||||
+3
-1
@@ -32,4 +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);
|
||||
|
||||
Reference in New Issue
Block a user