teknoraver / rpms / systemd

Forked from rpms/systemd a month ago
Clone

Blame SOURCES/0197-shared-install-split-UNIT_FILE_SYMLINK-into-two-stat.patch

594167
From e2d699c92944c6251f9de161c9e3ae93d915c4e0 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 15:50:16 +0100
594167
Subject: [PATCH] shared/install: split UNIT_FILE_SYMLINK into two states
594167
594167
The two states are distinguished, but are treated everywhere identically,
594167
so there is no difference in behaviour except for slighlty different log
594167
output.
594167
594167
(cherry picked from commit 48ed75adabef3427767038fa155e55b3b0d48f35)
594167
594167
Related: #2082131
594167
---
594167
 src/basic/unit-file.c |  6 ++++--
594167
 src/shared/install.c  | 14 +++++++++-----
594167
 src/shared/install.h  |  3 ++-
594167
 3 files changed, 15 insertions(+), 8 deletions(-)
594167
594167
diff --git a/src/basic/unit-file.c b/src/basic/unit-file.c
594167
index 2474648ceb..7c1ae515e1 100644
594167
--- a/src/basic/unit-file.c
594167
+++ b/src/basic/unit-file.c
594167
@@ -282,7 +282,9 @@ int unit_file_resolve_symlink(
594167
          *
594167
          * If resolve_destination_target is true, an absolute path will be returned.
594167
          * If not, an absolute path is returned for linked unit files, and a relative
594167
-         * path otherwise. */
594167
+         * path otherwise.
594167
+         *
594167
+         * Returns an error, false if this is an alias, true if it's a linked unit file. */
594167
 
594167
         assert(filename);
594167
         assert(ret_destination);
594167
@@ -364,7 +366,7 @@ int unit_file_resolve_symlink(
594167
         }
594167
 
594167
         *ret_destination = TAKE_PTR(dst);
594167
-        return 0;
594167
+        return !tail;  /* true if linked unit file */
594167
 }
594167
 
594167
 int unit_file_build_name_map(
594167
diff --git a/src/shared/install.c b/src/shared/install.c
594167
index f911d527df..b33f7d4bc1 100644
594167
--- a/src/shared/install.c
594167
+++ b/src/shared/install.c
594167
@@ -93,8 +93,9 @@ void unit_file_presets_freep(UnitFilePresets *p) {
594167
 
594167
 static const char *const unit_file_type_table[_UNIT_FILE_TYPE_MAX] = {
594167
         [UNIT_FILE_TYPE_REGULAR] = "regular",
594167
-        [UNIT_FILE_TYPE_SYMLINK] = "symlink",
594167
-        [UNIT_FILE_TYPE_MASKED] = "masked",
594167
+        [UNIT_FILE_TYPE_LINKED]  = "linked",
594167
+        [UNIT_FILE_TYPE_ALIAS]   = "alias",
594167
+        [UNIT_FILE_TYPE_MASKED]  = "masked",
594167
 };
594167
 
594167
 DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(unit_file_type, UnitFileType);
594167
@@ -1404,14 +1405,17 @@ static int unit_file_load_or_readlink(
594167
                                       true, &info->symlink_target);
594167
         if (r < 0)
594167
                 return r;
594167
+        bool outside_search_path = r > 0;
594167
 
594167
         r = null_or_empty_path_with_root(info->symlink_target, lp->root_dir);
594167
         if (r < 0 && r != -ENOENT)
594167
                 return log_debug_errno(r, "Failed to stat %s: %m", info->symlink_target);
594167
         if (r > 0)
594167
                 info->type = UNIT_FILE_TYPE_MASKED;
594167
+        else if (outside_search_path)
594167
+                info->type = UNIT_FILE_TYPE_LINKED;
594167
         else
594167
-                info->type = UNIT_FILE_TYPE_SYMLINK;
594167
+                info->type = UNIT_FILE_TYPE_ALIAS;
594167
 
594167
         return 0;
594167
 }
594167
@@ -1550,7 +1554,7 @@ static int install_info_follow(
594167
         assert(ctx);
594167
         assert(info);
594167
 
594167
-        if (info->type != UNIT_FILE_TYPE_SYMLINK)
594167
+        if (!IN_SET(info->type, UNIT_FILE_TYPE_ALIAS, UNIT_FILE_TYPE_LINKED))
594167
                 return -EINVAL;
594167
         if (!info->symlink_target)
594167
                 return -EINVAL;
594167
@@ -1591,7 +1595,7 @@ static int install_info_traverse(
594167
                 return r;
594167
 
594167
         i = start;
594167
-        while (i->type == UNIT_FILE_TYPE_SYMLINK) {
594167
+        while (IN_SET(i->type, UNIT_FILE_TYPE_ALIAS, UNIT_FILE_TYPE_LINKED)) {
594167
                 /* Follow the symlink */
594167
 
594167
                 if (++k > UNIT_FILE_FOLLOW_SYMLINK_MAX)
594167
diff --git a/src/shared/install.h b/src/shared/install.h
594167
index dba6987406..95427537f2 100644
594167
--- a/src/shared/install.h
594167
+++ b/src/shared/install.h
594167
@@ -70,7 +70,8 @@ struct UnitFileList {
594167
 
594167
 enum UnitFileType {
594167
         UNIT_FILE_TYPE_REGULAR,
594167
-        UNIT_FILE_TYPE_SYMLINK,
594167
+        UNIT_FILE_TYPE_LINKED,
594167
+        UNIT_FILE_TYPE_ALIAS,
594167
         UNIT_FILE_TYPE_MASKED,
594167
         _UNIT_FILE_TYPE_MAX,
594167
         _UNIT_FILE_TYPE_INVALID = -EINVAL,