nspawn: fix comparisons of versions with non-numerical suffixes

See a2b0cd3f5a. When -Dshared-lib-tag is used,
libsystemd-shared.so and libsystemd-core.so get a suffix which breaks the
parsing done by systemd_installation_has_version(). We can assume that the
tag will be something like "251-rc1-1.fc37" that is currently used in Fedora.
(Anything that does *not* start with the version would be completely crazy.)
By switching to strverscmp_improved() we simplify the code and fix comparisons
with such versions.

$ build/test-nspawn-util /var/lib/machines/rawhide
...
Found libsystemd shared at "/var/lib/machines/rawhide/lib/systemd/libsystemd-shared-251-rc1-1.fc37.so.so", version 251-rc1-1.fc37 (OK).
/var/lib/machines/rawhide has systemd >= 251: yes
...

I noticed this when I started a systemd-nspawn container with Redora rawhide
and got the message "Not running with unified cgroup hierarchy, LSM BPF is not
supported". I thought the message is in error, but it was actually correct:
nspawn was misdetecting that the container does not sport new-enough systemd
to support cgroups-v2.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2022-04-07 18:19:03 +02:00
parent c9394f4f93
commit 7e6821ed4e
4 changed files with 15 additions and 22 deletions
+5 -5
View File
@@ -2,17 +2,17 @@
#include "nspawn-util.h"
#include "string-util.h"
#include "strv.h"
#include "tests.h"
TEST(systemd_installation_has_version) {
static const unsigned versions[] = {0, 231, PROJECT_VERSION, 999};
int r;
for (size_t i = 0; i < ELEMENTSOF(versions); i++) {
r = systemd_installation_has_version(saved_argv[1], versions[i]);
FOREACH_STRING(version, "0", "231", STRINGIFY(PROJECT_VERSION), "999") {
r = systemd_installation_has_version(saved_argv[1], version);
assert_se(r >= 0);
log_info("%s has systemd >= %u: %s",
saved_argv[1] ?: "Current installation", versions[i], yes_no(r));
log_info("%s has systemd >= %s: %s",
saved_argv[1] ?: "Current installation", version, yes_no(r));
}
}