daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
65878a
From 8d32393e5a3fbc12371edf69830d0258a097211f Mon Sep 17 00:00:00 2001
65878a
From: Lennart Poettering <lennart@poettering.net>
65878a
Date: Tue, 17 Jun 2014 00:53:49 +0200
65878a
Subject: [PATCH] install: make sure that --root= mode doesn't make us consider
65878a
 all units outside of search path
65878a
65878a
(cherry picked from commit 8f294b45cbb627d31342f6a79444be59ce7e2274)
65878a
65878a
Related: #1111199
65878a
---
65878a
 src/shared/install.c | 41 +++++++++++++++++++++++++++++++++++++----
65878a
 src/shared/util.c    | 16 ----------------
65878a
 src/shared/util.h    |  1 -
65878a
 3 files changed, 37 insertions(+), 21 deletions(-)
65878a
65878a
diff --git a/src/shared/install.c b/src/shared/install.c
65878a
index 871de78..7dad66d 100644
65878a
--- a/src/shared/install.c
65878a
+++ b/src/shared/install.c
65878a
@@ -47,6 +47,37 @@ typedef struct {
65878a
 #define _cleanup_lookup_paths_free_ _cleanup_(lookup_paths_free)
65878a
 #define _cleanup_install_context_done_ _cleanup_(install_context_done)
65878a
 
65878a
+static int in_search_path(const char *path, char **search, const char *root_dir) {
65878a
+        _cleanup_free_ char *parent = NULL;
65878a
+        char **i;
65878a
+        int r;
65878a
+
65878a
+        assert(path);
65878a
+
65878a
+        r = path_get_parent(path, &parent);
65878a
+        if (r < 0)
65878a
+                return r;
65878a
+
65878a
+        STRV_FOREACH(i, search) {
65878a
+                _cleanup_free_ char *buf = NULL;
65878a
+                const char *p;
65878a
+
65878a
+                if (root_dir) {
65878a
+                        buf = strjoin(root_dir, "/", *i, NULL);
65878a
+                        if (!buf)
65878a
+                                return -ENOMEM;
65878a
+
65878a
+                        p = buf;
65878a
+                } else
65878a
+                        p = *i;
65878a
+
65878a
+                if (path_equal(parent, p))
65878a
+                        return 1;
65878a
+        }
65878a
+
65878a
+        return 0;
65878a
+}
65878a
+
65878a
 static int lookup_paths_init_from_scope(LookupPaths *paths,
65878a
                                         UnitFileScope scope,
65878a
                                         const char *root_dir) {
65878a
@@ -741,7 +772,7 @@ int unit_file_link(
65878a
                         continue;
65878a
                 }
65878a
 
65878a
-                q = in_search_path(*i, paths.unit_path);
65878a
+                q = in_search_path(*i, paths.unit_path, root_dir);
65878a
                 if (q < 0)
65878a
                         return q;
65878a
 
65878a
@@ -1296,6 +1327,7 @@ static int install_info_symlink_link(
65878a
                 InstallInfo *i,
65878a
                 LookupPaths *paths,
65878a
                 const char *config_path,
65878a
+                const char *root_dir,
65878a
                 bool force,
65878a
                 UnitFileChange **changes,
65878a
                 unsigned *n_changes) {
65878a
@@ -1308,7 +1340,7 @@ static int install_info_symlink_link(
65878a
         assert(config_path);
65878a
         assert(i->path);
65878a
 
65878a
-        r = in_search_path(i->path, paths->unit_path);
65878a
+        r = in_search_path(i->path, paths->unit_path, root_dir);
65878a
         if (r != 0)
65878a
                 return r;
65878a
 
65878a
@@ -1323,6 +1355,7 @@ static int install_info_apply(
65878a
                 InstallInfo *i,
65878a
                 LookupPaths *paths,
65878a
                 const char *config_path,
65878a
+                const char *root_dir,
65878a
                 bool force,
65878a
                 UnitFileChange **changes,
65878a
                 unsigned *n_changes) {
65878a
@@ -1343,7 +1376,7 @@ static int install_info_apply(
65878a
         if (r == 0)
65878a
                 r = q;
65878a
 
65878a
-        q = install_info_symlink_link(i, paths, config_path, force, changes, n_changes);
65878a
+        q = install_info_symlink_link(i, paths, config_path, root_dir, force, changes, n_changes);
65878a
         if (r == 0)
65878a
                 r = q;
65878a
 
65878a
@@ -1383,7 +1416,7 @@ static int install_context_apply(
65878a
                 } else if (r >= 0)
65878a
                         r += q;
65878a
 
65878a
-                q = install_info_apply(i, paths, config_path, force, changes, n_changes);
65878a
+                q = install_info_apply(i, paths, config_path, root_dir, force, changes, n_changes);
65878a
                 if (r >= 0 && q < 0)
65878a
                         r = q;
65878a
         }
65878a
diff --git a/src/shared/util.c b/src/shared/util.c
65878a
index e313ea9..fc1f765 100644
65878a
--- a/src/shared/util.c
65878a
+++ b/src/shared/util.c
65878a
@@ -4490,22 +4490,6 @@ int dirent_ensure_type(DIR *d, struct dirent *de) {
65878a
         return 0;
65878a
 }
65878a
 
65878a
-int in_search_path(const char *path, char **search) {
65878a
-        char **i;
65878a
-        _cleanup_free_ char *parent = NULL;
65878a
-        int r;
65878a
-
65878a
-        r = path_get_parent(path, &parent);
65878a
-        if (r < 0)
65878a
-                return r;
65878a
-
65878a
-        STRV_FOREACH(i, search)
65878a
-                if (path_equal(parent, *i))
65878a
-                        return 1;
65878a
-
65878a
-        return 0;
65878a
-}
65878a
-
65878a
 int get_files_in_directory(const char *path, char ***list) {
65878a
         _cleanup_closedir_ DIR *d = NULL;
65878a
         size_t bufsize = 0, n = 0;
65878a
diff --git a/src/shared/util.h b/src/shared/util.h
65878a
index 3f30917..ec18d2c 100644
65878a
--- a/src/shared/util.h
65878a
+++ b/src/shared/util.h
65878a
@@ -475,7 +475,6 @@ int glob_extend(char ***strv, const char *path);
65878a
 
65878a
 int dirent_ensure_type(DIR *d, struct dirent *de);
65878a
 
65878a
-int in_search_path(const char *path, char **search);
65878a
 int get_files_in_directory(const char *path, char ***list);
65878a
 
65878a
 char *strjoin(const char *x, ...) _sentinel_;