diff options
author | Iago López Galeiras <iago@endocode.com> | 2015-05-13 15:45:49 +0200 |
---|---|---|
committer | Sven Eden <yamakuzure@gmx.net> | 2017-03-14 09:56:08 +0100 |
commit | f0b159f2e7b4ac8a75997834d240459f5436d36e (patch) | |
tree | 507d45ce5afb9d10ef39767ec9f3bc4c1b7950bc | |
parent | 15658a4bc930a9b4b9511256431c2e2383dad0f5 (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/shared/util.c | 22 | ||||
-rw-r--r-- | src/shared/util.h | 1 |
2 files changed, 23 insertions, 0 deletions
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); |