summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
authorIago López Galeiras <iago@endocode.com>2015-05-13 15:45:49 +0200
committerSven Eden <yamakuzure@gmx.net>2017-03-14 09:56:08 +0100
commitf0b159f2e7b4ac8a75997834d240459f5436d36e (patch)
tree507d45ce5afb9d10ef39767ec9f3bc4c1b7950bc /src/shared/util.c
parent15658a4bc930a9b4b9511256431c2e2383dad0f5 (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.
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c22
1 files changed, 22 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;