diff options
author | Iago López Galeiras <iago@endocode.com> | 2015-05-13 15:45:49 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-05-13 16:03:07 +0200 |
commit | 875e1014dd9d55cd0692dcce843598cffb2d09b0 (patch) | |
tree | 56dc288f358172ede7ab92d9b3fab5e409d3cdfd | |
parent | 54b4755f15438c86991d5a4eaadc47150f7e5a84 (diff) |
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.
-rw-r--r-- | src/nspawn/nspawn.c | 10 | ||||
-rw-r--r-- | src/shared/util.c | 22 | ||||
-rw-r--r-- | src/shared/util.h | 1 |
3 files changed, 30 insertions, 3 deletions
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"); } } diff --git a/src/shared/util.c b/src/shared/util.c index 466dce439f..72711e133a 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -2765,6 +2765,28 @@ int symlink_atomic(const char *from, const char *to) { return 0; } +int symlink_idempotent(const char *from, const char *to) { + _cleanup_free_ char *p = NULL; + int r; + + assert(from); + assert(to); + + if (symlink(from, to) < 0) { + if (errno != EEXIST) + return -errno; + + r = readlink_malloc(to, &p); + if (r < 0) + return r; + + if (!streq(p, from)) + return -EINVAL; + } + + return 0; +} + int mknod_atomic(const char *path, mode_t mode, dev_t dev) { _cleanup_free_ char *t = NULL; int r; diff --git a/src/shared/util.h b/src/shared/util.h index 4a67d5c716..8565fd6e48 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -404,6 +404,7 @@ bool machine_name_is_valid(const char *s) _pure_; char* strshorten(char *s, size_t l); +int symlink_idempotent(const char *from, const char *to); int symlink_atomic(const char *from, const char *to); int mknod_atomic(const char *path, mode_t mode, dev_t dev); |