and 'block-weak' inhibitor modes were added, if taken they will make
the inhibitor lock work as in the previous versions.
+ * systemd-nspawn will now mount the unified cgroup hierarchy into a
+ container if no systemd installation is found in a container's root
+ filesystem. `$SYSTEMD_NSPAWN_UNIFIED_HIERARCHY=0` can be used to override
+ this behavior.
+
— <place>, <date>
CHANGES WITH 256:
#include "string-util.h"
int systemd_installation_has_version(const char *root, const char *minimal_version) {
+ bool found = false;
int r;
/* Try to guess if systemd installation is later than the specified version. This
continue;
*t2 = '\0';
+ found = true;
+
r = strverscmp_improved(t, minimal_version);
log_debug("Found libsystemd shared at \"%s.so\", version %s (%s).",
*name, t,
}
}
- return false;
+ return !found ? -ENOENT : false;
}
return log_error_errno(r, "Failed to determine whether we are in all unified mode.");
if (r > 0) {
/* Unified cgroup hierarchy support was added in 230. Unfortunately the detection
- * routine only detects 231, so we'll have a false negative here for 230. */
+ * routine only detects 231, so we'll have a false negative here for 230. If there is no
+ * systemd installation in the container, we use the unified cgroup hierarchy. */
r = systemd_installation_has_version(directory, "230");
- if (r < 0)
+ if (r < 0 && r != -ENOENT)
return log_error_errno(r, "Failed to determine systemd version in container: %m");
- if (r > 0)
- arg_unified_cgroup_hierarchy = CGROUP_UNIFIED_ALL;
- else
+ if (r == 0)
arg_unified_cgroup_hierarchy = CGROUP_UNIFIED_NONE;
+ else
+ arg_unified_cgroup_hierarchy = CGROUP_UNIFIED_ALL;
} else if (cg_unified_controller(SYSTEMD_CGROUP_CONTROLLER) > 0) {
- /* Mixed cgroup hierarchy support was added in 233 */
+ /* Mixed cgroup hierarchy support was added in 233. If there is no systemd installation in
+ * the container, we use the unified cgroup hierarchy. */
r = systemd_installation_has_version(directory, "233");
- if (r < 0)
+ if (r < 0 && r != -ENOENT)
return log_error_errno(r, "Failed to determine systemd version in container: %m");
- if (r > 0)
- arg_unified_cgroup_hierarchy = CGROUP_UNIFIED_SYSTEMD;
- else
+ if (r == 0)
arg_unified_cgroup_hierarchy = CGROUP_UNIFIED_NONE;
+ else
+ arg_unified_cgroup_hierarchy = CGROUP_UNIFIED_SYSTEMD;
} else
arg_unified_cgroup_hierarchy = CGROUP_UNIFIED_NONE;
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "nspawn-util.h"
-#include "string-util.h"
+#include "rm-rf.h"
#include "strv.h"
#include "tests.h"
+#include "tmpfile-util.h"
TEST(systemd_installation_has_version) {
int r;
FOREACH_STRING(version, "0", "231", PROJECT_VERSION_FULL, "999") {
r = systemd_installation_has_version(saved_argv[1], version);
- assert_se(r >= 0);
+ /* The build environment may not have a systemd installation. */
+ if (r == -ENOENT)
+ continue;
+ ASSERT_OK(r);
log_info("%s has systemd >= %s: %s",
saved_argv[1] ?: "Current installation", version, yes_no(r));
}
+
+ _cleanup_(rm_rf_physical_and_freep) char *t = NULL;
+ ASSERT_OK(mkdtemp_malloc(NULL, &t));
+
+ ASSERT_ERROR(systemd_installation_has_version(t, PROJECT_VERSION_FULL), ENOENT);
}
/* This program can be called with a path to an installation root.