chiark / gitweb /
nspawn: skip symlink to a combined cgroup hierarchy if it already exists
[elogind.git] / src / shared / util.c
index b885a46e439fb3a5a197007b4ff90690fa0c074e..9b67dd8296fde6fab7ae3b862bf7ce63fc21e015 100644 (file)
@@ -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;