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