chiark / gitweb /
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)
committerSven Eden <yamakuzure@gmx.net>
Tue, 14 Mar 2017 08:56:08 +0000 (09:56 +0100)
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
src/shared/util.h

index b885a46e439fb3a5a197007b4ff90690fa0c074e..9b67dd8296fde6fab7ae3b862bf7ce63fc21e015 100644 (file)
@@ -2766,6 +2766,28 @@ int symlink_atomic(const char *from, const char *to) {
         return 0;
 }
 
         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;
 int mknod_atomic(const char *path, mode_t mode, dev_t dev) {
         _cleanup_free_ char *t = NULL;
         int r;
index bfa3e4429c298af829c857e6d8fb5c7a6f30803b..b4e0b778ae335c8b0a66ad983cd0adbf85a86589 100644 (file)
@@ -405,6 +405,7 @@ bool machine_name_is_valid(const char *s) _pure_;
 
 char* strshorten(char *s, size_t l);
 
 
 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);
 
 int symlink_atomic(const char *from, const char *to);
 int mknod_atomic(const char *path, mode_t mode, dev_t dev);