[systemd-devel] [PATCH 2/2] nspawn: skip symlink to a combined cgroup hierarchy if it already exists
Iago López Galeiras
iago at endocode.com
Wed May 13 02:15:40 PDT 2015
If a symlink to a combined cgroup hierarchy already exists and points to
the right path, skip it. This avoids an error when the cgroups are set
manually before calling nspawn.
---
src/nspawn/nspawn.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index c67cab2..cc0b84f 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -1113,7 +1113,7 @@ static int mount_cgroup(const char *dest) {
} else if (r < 0)
return log_error_errno(r, "Failed to read link %s: %m", origin);
else {
- _cleanup_free_ char *target = NULL;
+ _cleanup_free_ char *target = NULL, *p = NULL;
target = strjoin(dest, "/sys/fs/cgroup/", controller, NULL);
if (!target)
@@ -1130,8 +1130,18 @@ static int mount_cgroup(const char *dest) {
if (r < 0)
return r;
- if (symlink(combined, target) < 0)
+ if (symlink(combined, target) < 0) {
+ if (errno == EEXIST) {
+ r = readlink_malloc(target, &p);
+ if (r < 0)
+ return log_error_errno(r, "Failed to read link %s: %m", target);
+ else if (!streq(p, combined)) {
+ log_error("Invalid existing symlink for combined hierarchy");
+ return -EINVAL;
+ }
+ } else
return log_error_errno(errno, "Failed to create symlink for combined hierarchy: %m");
+ }
}
}
--
2.4.0
More information about the systemd-devel
mailing list