- if (!streq(i->argument, x)) {
- free(x);
- log_error("%s is not the right symlinks.", i->path);
- return -EEXIST;
+ if (errno != EEXIST) {
+ log_error("symlink(%s, %s) failed: %m", i->argument, i->path);
+ return -errno;
+ }
+
+ r = readlink_malloc(i->path, &x);
+ if (r < 0 || !streq(i->argument, x)) {
+
+ if (i->force) {
+ label_context_set(i->path, S_IFLNK);
+ r = symlink_atomic(i->argument, i->path);
+ label_context_clear();
+
+ if (r < 0) {
+ log_error("symlink(%s, %s) failed: %s", i->argument, i->path, strerror(-r));
+ return r;
+ }
+ } else {
+ log_debug("%s is not a symlink or does not point to the correct path.", i->path);
+ return 0;
+ }
+ }