]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nspawn: skip symlink to a combined cgroup hierarchy if it already exists
authorIago López Galeiras <iago@endocode.com>
Wed, 13 May 2015 13:45:49 +0000 (15:45 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 13 May 2015 14:03:07 +0000 (16:03 +0200)
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
src/shared/util.c
src/shared/util.h

index 1ba55932bf460fc46639e687b9be60144b9b669b..fbf23440f7ecff9e5d147b50e445be848e221a4a 100644 (file)
@@ -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");
                 }
         }
 
index 466dce439fa036372955b8d707c5a0f1a5e22f42..72711e133a4e9d23f6473a4a431668f9cf621855 100644 (file)
@@ -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;
index 4a67d5c7164d9a3580ce4aced6785d950abab653..8565fd6e48f61fc0ec04835346604685012b6a4a 100644 (file)
@@ -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);