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