]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Change symlinks params to target & linkpath
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 16 Sep 2025 14:58:34 +0000 (16:58 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Thu, 18 Sep 2025 11:36:50 +0000 (12:36 +0100)
This is what the symlinkat.2 man page uses.

The old naming with 'to' and 'from', where 'to' is the symlink name
and 'from' is the symlink target is very confusing.

Follow-up for 892838911b21113a20a8ef0ad4f2e5336753afc8.

src/basic/fs-util.c
src/basic/fs-util.h
src/shared/generator.c

index 9fb6f5d0b82d8eb884d585c134c4e46c8ef4f662..a12cfd33c4f822b5bacbfe99f8340935ac6d1659 100644 (file)
@@ -423,76 +423,76 @@ int touch(const char *path) {
         return touch_file(path, false, USEC_INFINITY, UID_INVALID, GID_INVALID, MODE_INVALID);
 }
 
-int symlinkat_idempotent(const char *from, int atfd, const char *to, bool make_relative) {
+int symlinkat_idempotent(const char *target, int atfd, const char *linkpath, bool make_relative) {
         _cleanup_free_ char *relpath = NULL;
         int r;
 
-        assert(from);
-        assert(to);
+        assert(target);
+        assert(linkpath);
 
         if (make_relative) {
-                r = path_make_relative_parent(to, from, &relpath);
+                r = path_make_relative_parent(linkpath, target, &relpath);
                 if (r < 0)
                         return r;
 
-                from = relpath;
+                target = relpath;
         }
 
-        if (symlinkat(from, atfd, to) < 0) {
+        if (symlinkat(target, atfd, linkpath) < 0) {
                 _cleanup_free_ char *p = NULL;
 
                 if (errno != EEXIST)
                         return -errno;
 
-                r = readlinkat_malloc(atfd, to, &p);
+                r = readlinkat_malloc(atfd, linkpath, &p);
                 if (r == -EINVAL) /* Not a symlink? In that case return the original error we encountered: -EEXIST */
                         return -EEXIST;
                 if (r < 0) /* Any other error? In that case propagate it as is */
                         return r;
 
-                if (!streq(p, from)) /* Not the symlink we want it to be? In that case, propagate the original -EEXIST */
+                if (!streq(p, target)) /* Not the symlink we want it to be? In that case, propagate the original -EEXIST */
                         return -EEXIST;
         }
 
         return 0;
 }
 
-int symlinkat_atomic_full(const char *from, int atfd, const char *to, SymlinkFlags flags) {
+int symlinkat_atomic_full(const char *target, int atfd, const char *linkpath, SymlinkFlags flags) {
         int r;
 
-        assert(from);
-        assert(to);
+        assert(target);
+        assert(linkpath);
 
         _cleanup_free_ char *relpath = NULL;
         if (FLAGS_SET(flags, SYMLINK_MAKE_RELATIVE)) {
-                r = path_make_relative_parent(to, from, &relpath);
+                r = path_make_relative_parent(linkpath, target, &relpath);
                 if (r < 0)
                         return r;
 
-                from = relpath;
+                target = relpath;
         }
 
         _cleanup_free_ char *t = NULL;
-        r = tempfn_random(to, NULL, &t);
+        r = tempfn_random(linkpath, NULL, &t);
         if (r < 0)
                 return r;
 
         bool call_label_ops_post = false;
         if (FLAGS_SET(flags, SYMLINK_LABEL)) {
-                r = label_ops_pre(atfd, to, S_IFLNK);
+                r = label_ops_pre(atfd, linkpath, S_IFLNK);
                 if (r < 0)
                         return r;
 
                 call_label_ops_post = true;
         }
 
-        r = RET_NERRNO(symlinkat(from, atfd, t));
+        r = RET_NERRNO(symlinkat(target, atfd, t));
         if (call_label_ops_post)
                 RET_GATHER(r, label_ops_post(atfd, t, /* created= */ r >= 0));
         if (r < 0)
                 return r;
 
-        r = RET_NERRNO(renameat(atfd, t, atfd, to));
+        r = RET_NERRNO(renameat(atfd, t, atfd, linkpath));
         if (r < 0) {
                 (void) unlinkat(atfd, t, 0);
                 return r;
index 74c1411556155c82b21ce37e01ca663fc0e9201f..1c4b88e53b7fbfee19165e283564f4c48811ed75 100644 (file)
@@ -47,9 +47,9 @@ int touch_fd(int fd, usec_t stamp);
 int touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gid, mode_t mode);
 int touch(const char *path);
 
-int symlinkat_idempotent(const char *from, int atfd, const char *to, bool make_relative);
-static inline int symlink_idempotent(const char *from, const char *to, bool make_relative) {
-        return symlinkat_idempotent(from, AT_FDCWD, to, make_relative);
+int symlinkat_idempotent(const char *target, int atfd, const char *linkpath, bool make_relative);
+static inline int symlink_idempotent(const char *target, const char *linkpath, bool make_relative) {
+        return symlinkat_idempotent(target, AT_FDCWD, linkpath, make_relative);
 }
 
 typedef enum SymlinkFlags {
@@ -57,9 +57,9 @@ typedef enum SymlinkFlags {
         SYMLINK_LABEL         = 1 << 1,
 } SymlinkFlags;
 
-int symlinkat_atomic_full(const char *from, int atfd, const char *to, SymlinkFlags flags);
-static inline int symlink_atomic(const char *from, const char *to) {
-        return symlinkat_atomic_full(from, AT_FDCWD, to, 0);
+int symlinkat_atomic_full(const char *target, int atfd, const char *linkpath, SymlinkFlags flags);
+static inline int symlink_atomic(const char *target, const char *linkpath) {
+        return symlinkat_atomic_full(target, AT_FDCWD, linkpath, 0);
 }
 
 int mknodat_atomic(int atfd, const char *path, mode_t mode, dev_t dev);
index 3df988830d2e038671b01f3b1245f023cfce93e8..78dd34ccb59a229c0759b301f339d2b5910a4061 100644 (file)
 #include "tmpfile-util.h"
 #include "unit-name.h"
 
-static int symlink_unless_exists(const char *from, const char *to) {
-        (void) mkdir_parents(to, 0755);
+static int symlink_unless_exists(const char *target, const char *linkpath) {
+        (void) mkdir_parents(linkpath, 0755);
 
-        if (symlink(from, to) < 0 && errno != EEXIST)
-                return log_error_errno(errno, "Failed to create symlink %s: %m", to);
+        if (symlink(target, linkpath) < 0 && errno != EEXIST)
+                return log_error_errno(errno, "Failed to create symlink %s: %m", linkpath);
         return 0;
 }