From f0b159f2e7b4ac8a75997834d240459f5436d36e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Iago=20L=C3=B3pez=20Galeiras?= Date: Wed, 13 May 2015 15:45:49 +0200 Subject: [PATCH 1/1] 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/shared/util.c | 22 ++++++++++++++++++++++ src/shared/util.h | 1 + 2 files changed, 23 insertions(+) diff --git a/src/shared/util.c b/src/shared/util.c index b885a46e4..9b67dd829 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -2766,6 +2766,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 bfa3e4429..b4e0b778a 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -405,6 +405,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); -- 2.30.2