diff options
author | Lennart Poettering <lennart@poettering.net> | 2023-06-20 18:30:40 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2023-06-20 19:02:31 +0200 |
commit | ffe5aba60c970ae0a01285215a200b042a6203ff (patch) | |
tree | b9b0b780795502bc02f6ed86844f1f710f6283a1 /src/analyze/analyze-compare-versions.c | |
parent | string-util: move version_is_valid() into generic code (diff) | |
download | systemd-ffe5aba60c970ae0a01285215a200b042a6203ff.tar.xz systemd-ffe5aba60c970ae0a01285215a200b042a6203ff.zip |
analyze: also check for version string validity
It's highly interesting to see if tools such as systemd-sysupdate
consider a version valid, hence let's output that too (though
gracefully, not fatally)
Diffstat (limited to 'src/analyze/analyze-compare-versions.c')
-rw-r--r-- | src/analyze/analyze-compare-versions.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/analyze/analyze-compare-versions.c b/src/analyze/analyze-compare-versions.c index 07b52a55f2..d210fab672 100644 --- a/src/analyze/analyze-compare-versions.c +++ b/src/analyze/analyze-compare-versions.c @@ -9,17 +9,26 @@ #include "strv.h" int verb_compare_versions(int argc, char *argv[], void *userdata) { + const char *v1 = ASSERT_PTR(argv[1]), *v2 = ASSERT_PTR(argv[argc-1]); int r; assert(IN_SET(argc, 3, 4)); assert(argv); + /* We only output a warning on invalid version strings (instead of failing), since the comparison + * functions try to handle invalid strings graceful and it's still interesting to see what the + * comparison result will be. */ + if (!version_is_valid(v1)) + log_warning("Version string 1 is not valid, comparing anyway: %s", v1); + if (!version_is_valid(v2)) + log_warning("Version string 2 is not valid, comparing anyway: %s", v2); + if (argc == 3) { - r = strverscmp_improved(ASSERT_PTR(argv[1]), ASSERT_PTR(argv[2])); + r = strverscmp_improved(v1, v2); printf("%s %s %s\n", - isempty(argv[1]) ? "''" : argv[1], + isempty(v1) ? "''" : v1, comparison_operator(r), - isempty(argv[2]) ? "''" : argv[2]); + isempty(v2) ? "''" : v2); /* This matches the exit convention used by rpmdev-vercmp. * We don't use named values because 11 and 12 don't have names. */ @@ -28,12 +37,13 @@ int verb_compare_versions(int argc, char *argv[], void *userdata) { } else { const char *op = ASSERT_PTR(argv[2]); CompareOperator operator; + assert(argc == 4); operator = parse_compare_operator(&op, COMPARE_ALLOW_TEXTUAL); if (operator < 0 || !isempty(op)) return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Unknown operator \"%s\".", op); - r = version_or_fnmatch_compare(operator, ASSERT_PTR(argv[1]), ASSERT_PTR(argv[3])); + r = version_or_fnmatch_compare(operator, v1, v2); if (r < 0) return log_error_errno(r, "Failed to compare versions: %m"); |