teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0269-shared-install-do-not-prefix-created-symlink-with-ro.patch

65878a
From 6dadf44d7062c38c3f4f782da3cd88114dceb959 Mon Sep 17 00:00:00 2001
65878a
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
65878a
Date: Mon, 21 Apr 2014 19:17:40 -0400
65878a
Subject: [PATCH] shared/install: do not prefix created symlink with root path
65878a
65878a
Before: /var/tmp/inst1//etc/systemd/system/default.target -> /var/tmp/inst1//usr/lib/systemd/system/graphical.target
65878a
After: /var/tmp/inst1/etc/systemd/system/default.target -> /usr/lib/systemd/system/graphical.target
65878a
65878a
(cherry picked from commit 62b002337727093c21d020c730bd65971f7783a7)
65878a
65878a
Related: #1111199
65878a
---
65878a
 src/shared/install.c | 89 +++++++++++++++++++++++++---------------------------
65878a
 1 file changed, 43 insertions(+), 46 deletions(-)
65878a
65878a
diff --git a/src/shared/install.c b/src/shared/install.c
65878a
index 7dad66d..955a9bc 100644
65878a
--- a/src/shared/install.c
65878a
+++ b/src/shared/install.c
65878a
@@ -1073,67 +1073,64 @@ static int unit_file_search(
65878a
         assert(info);
65878a
         assert(paths);
65878a
 
65878a
-        if (info->path)
65878a
-                return unit_file_load(c, info, info->path, allow_symlink);
65878a
+        if (info->path) {
65878a
+                char *full_path = NULL;
65878a
+
65878a
+                if (!isempty(root_dir))
65878a
+                        full_path = strappenda(root_dir, info->path);
65878a
+
65878a
+                return unit_file_load(c, info, full_path ?: info->path, allow_symlink);
65878a
+        }
65878a
 
65878a
         assert(info->name);
65878a
 
65878a
         STRV_FOREACH(p, paths->unit_path) {
65878a
-                char *path = NULL;
65878a
-
65878a
-                if (isempty(root_dir))
65878a
-                        asprintf(&path, "%s/%s", *p, info->name);
65878a
-                else
65878a
-                        asprintf(&path, "%s/%s/%s", root_dir, *p, info->name);
65878a
+                _cleanup_free_ char *path = NULL, *full_path = NULL;
65878a
 
65878a
+                path = strjoin(*p, "/", info->name, NULL);
65878a
                 if (!path)
65878a
                         return -ENOMEM;
65878a
 
65878a
-                r = unit_file_load(c, info, path, allow_symlink);
65878a
+                if (!isempty(root_dir)) {
65878a
+                        full_path = strappend(root_dir, path);
65878a
+                        if (!full_path)
65878a
+                                return -ENOMEM;
65878a
+                }
65878a
 
65878a
-                if (r >= 0)
65878a
+                r = unit_file_load(c, info, full_path ?: path, allow_symlink);
65878a
+                if (r >= 0) {
65878a
                         info->path = path;
65878a
-                else {
65878a
-                        if (r == -ENOENT && unit_name_is_instance(info->name)) {
65878a
-                                /* Unit file doesn't exist, however instance enablement was requested.
65878a
-                                 * We will check if it is possible to load template unit file. */
65878a
-                                char *template = NULL,
65878a
-                                     *template_path = NULL,
65878a
-                                     *template_dir = NULL;
65878a
-
65878a
-                                template = unit_name_template(info->name);
65878a
-                                if (!template) {
65878a
-                                        free(path);
65878a
-                                        return -ENOMEM;
65878a
-                                }
65878a
+                        path = NULL;
65878a
+                } else if (r == -ENOENT && unit_name_is_instance(info->name)) {
65878a
+                        /* Unit file doesn't exist, however instance enablement was requested.
65878a
+                         * We will check if it is possible to load template unit file. */
65878a
+                        _cleanup_free_ char *template = NULL, *template_dir = NULL;
65878a
+
65878a
+                        template = unit_name_template(info->name);
65878a
+                        if (!template)
65878a
+                                return -ENOMEM;
65878a
 
65878a
-                                /* We will reuse path variable since we don't need it anymore. */
65878a
-                                template_dir = path;
65878a
-                                *(strrchr(path, '/') + 1) = '\0';
65878a
+                        /* We will reuse path variable since we don't need it anymore. */
65878a
+                        template_dir = path;
65878a
+                        *(strrchr(template_dir, '/') + 1) = '\0';
65878a
 
65878a
-                                template_path = strjoin(template_dir, template, NULL);
65878a
-                                if (!template_path) {
65878a
-                                        free(path);
65878a
-                                        free(template);
65878a
-                                        return -ENOMEM;
65878a
-                                }
65878a
+                        path = strappend(template_dir, template);
65878a
+                        if (!path)
65878a
+                                return -ENOMEM;
65878a
 
65878a
-                                /* Let's try to load template unit. */
65878a
-                                r = unit_file_load(c, info, template_path, allow_symlink);
65878a
-                                if (r >= 0) {
65878a
-                                        info->path = strdup(template_path);
65878a
-                                        if (!info->path) {
65878a
-                                                free(path);
65878a
-                                                free(template);
65878a
-                                                free(template_path);
65878a
-                                                return -ENOMEM;
65878a
-                                        }
65878a
-                                }
65878a
+                        if (!isempty(root_dir)) {
65878a
+                                free(full_path);
65878a
+                                full_path = strappend(root_dir, path);
65878a
+                                if (!full_path)
65878a
+                                        return -ENOMEM;
65878a
+                        }
65878a
 
65878a
-                                free(template);
65878a
-                                free(template_path);
65878a
+                        /* Let's try to load template unit. */
65878a
+                        r = unit_file_load(c, info, full_path ?: path, allow_symlink);
65878a
+                        if (r >= 0) {
65878a
+                                info->path = path;
65878a
+                                path = NULL;
65878a
                         }
65878a
-                        free(path);
65878a
                 }
65878a
 
65878a
                 if (r != -ENOENT && r != -ELOOP)