From 875e1014dd9d55cd0692dcce843598cffb2d09b0 Mon Sep 17 00:00:00 2001 From: Iago López Galeiras Date: Wed, 13 May 2015 15:45:49 +0200 Subject: nspawn: skip symlink to a combined cgroup hierarchy if it already exists 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 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/nspawn') diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 1ba55932bf..fbf23440f7 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -1325,7 +1325,6 @@ static int mount_cgroup(const char *dest) { if (r < 0) return log_error_errno(r, "Failed to determine our own cgroup path: %m"); - for (;;) { _cleanup_free_ char *controller = NULL, *origin = NULL, *combined = NULL; @@ -1365,8 +1364,13 @@ static int mount_cgroup(const char *dest) { if (r < 0) return r; - if (symlink(combined, target) < 0) - return log_error_errno(errno, "Failed to create symlink for combined hierarchy: %m"); + r = symlink_idempotent(combined, target); + if (r == -EINVAL) { + log_error("Invalid existing symlink for combined hierarchy"); + return r; + } + if (r < 0) + return log_error_errno(r, "Failed to create symlink for combined hierarchy: %m"); } } -- cgit v1.2.3-54-g00ecf