naccyde / rpms / systemd

Forked from rpms/systemd a year ago
Clone
594167
From 4ac4cc6e4b17dea8f071e260cd8d3eae68ba883d Mon Sep 17 00:00:00 2001
594167
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
594167
Date: Thu, 17 Mar 2022 11:46:03 +0100
594167
Subject: [PATCH] basic/unit-file: reverse negative conditional
594167
594167
Having the reverse condition first makes changes that I want to do
594167
later awkward, so reverse it as a separate step first.
594167
594167
(cherry picked from commit bd177c62158df97785af0d360c4fc9c266311d88)
594167
594167
Related: #2082131
594167
---
594167
 src/basic/unit-file.c | 32 ++++++++++++++++----------------
594167
 1 file changed, 16 insertions(+), 16 deletions(-)
594167
594167
diff --git a/src/basic/unit-file.c b/src/basic/unit-file.c
594167
index 6cf66b45cf..2474648ceb 100644
594167
--- a/src/basic/unit-file.c
594167
+++ b/src/basic/unit-file.c
594167
@@ -326,27 +326,16 @@ int unit_file_resolve_symlink(
594167
 
594167
         assert(path_is_absolute(simplified));
594167
 
594167
-        /* Check if the symlink goes outside of our search path.
594167
-         * If yes, it's a linked unit file or mask, and we don't care about the target name
594167
+        /* Check if the symlink remain inside of of our search path.
594167
+         * If yes, it is an alias. Verify that it is valid.
594167
+         *
594167
+         * If no, then this is a linked unit file or mask, and we don't care about the target name
594167
          * when loading units, and we return the link *source* (resolve_destination_target == false);
594167
          * When this is called for installation purposes, we want the final destination,
594167
          * so we return the *target*.
594167
-         *
594167
-         * Otherwise, let's verify that it's a good alias.
594167
          */
594167
         const char *tail = path_startswith_strv(simplified, search_path);
594167
-        if (!tail) {
594167
-                log_debug("Linked unit file: %s/%s → %s", dir, filename, simplified);
594167
-
594167
-                if (resolve_destination_target)
594167
-                        dst = TAKE_PTR(simplified);
594167
-                else {
594167
-                        dst = path_join(dir, filename);
594167
-                        if (!dst)
594167
-                                return log_oom();
594167
-                }
594167
-
594167
-        } else {
594167
+        if (tail) {  /* An alias */
594167
                 _cleanup_free_ char *target_name = NULL;
594167
 
594167
                 r = path_extract_filename(simplified, &target_name);
594167
@@ -361,6 +350,17 @@ int unit_file_resolve_symlink(
594167
                                     dir, filename, simplified);
594167
 
594167
                 dst = resolve_destination_target ? TAKE_PTR(simplified) : TAKE_PTR(target_name);
594167
+
594167
+        } else {
594167
+                log_debug("Linked unit file: %s/%s → %s", dir, filename, simplified);
594167
+
594167
+                if (resolve_destination_target)
594167
+                        dst = TAKE_PTR(simplified);
594167
+                else {
594167
+                        dst = path_join(dir, filename);
594167
+                        if (!dst)
594167
+                                return log_oom();
594167
+                }
594167
         }
594167
 
594167
         *ret_destination = TAKE_PTR(dst);