naccyde / rpms / systemd

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