summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-04-21 19:17:40 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-05-15 15:29:57 +0200
commit62b002337727093c21d020c730bd65971f7783a7 (patch)
tree272b0206367e7131c56e2236dc67d444d1791771
parent1e89266b761a80da2cfc1b6e7a2a80a1855dcf7a (diff)
shared/install: do not prefix created symlink with root path
Before: /var/tmp/inst1//etc/systemd/system/default.target -> /var/tmp/inst1//usr/lib/systemd/system/graphical.target After: /var/tmp/inst1/etc/systemd/system/default.target -> /usr/lib/systemd/system/graphical.target
-rw-r--r--src/shared/install.c89
1 files changed, 43 insertions, 46 deletions
diff --git a/src/shared/install.c b/src/shared/install.c
index 9ce94035b9..2822e61880 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -1037,67 +1037,64 @@ static int unit_file_search(
assert(info);
assert(paths);
- if (info->path)
- return unit_file_load(c, info, info->path, allow_symlink);
+ if (info->path) {
+ char *full_path = NULL;
+
+ if (!isempty(root_dir))
+ full_path = strappenda(root_dir, info->path);
+
+ return unit_file_load(c, info, full_path ?: info->path, allow_symlink);
+ }
assert(info->name);
STRV_FOREACH(p, paths->unit_path) {
- char *path = NULL;
-
- if (isempty(root_dir))
- asprintf(&path, "%s/%s", *p, info->name);
- else
- asprintf(&path, "%s/%s/%s", root_dir, *p, info->name);
+ _cleanup_free_ char *path = NULL, *full_path = NULL;
+ path = strjoin(*p, "/", info->name, NULL);
if (!path)
return -ENOMEM;
- r = unit_file_load(c, info, path, allow_symlink);
+ if (!isempty(root_dir)) {
+ full_path = strappend(root_dir, path);
+ if (!full_path)
+ return -ENOMEM;
+ }
- if (r >= 0)
+ r = unit_file_load(c, info, full_path ?: path, allow_symlink);
+ if (r >= 0) {
info->path = path;
- else {
- if (r == -ENOENT && unit_name_is_instance(info->name)) {
- /* Unit file doesn't exist, however instance enablement was requested.
- * We will check if it is possible to load template unit file. */
- char *template = NULL,
- *template_path = NULL,
- *template_dir = NULL;
-
- template = unit_name_template(info->name);
- if (!template) {
- free(path);
- return -ENOMEM;
- }
+ path = NULL;
+ } else if (r == -ENOENT && unit_name_is_instance(info->name)) {
+ /* Unit file doesn't exist, however instance enablement was requested.
+ * We will check if it is possible to load template unit file. */
+ _cleanup_free_ char *template = NULL, *template_dir = NULL;
+
+ template = unit_name_template(info->name);
+ if (!template)
+ return -ENOMEM;
- /* We will reuse path variable since we don't need it anymore. */
- template_dir = path;
- *(strrchr(path, '/') + 1) = '\0';
+ /* We will reuse path variable since we don't need it anymore. */
+ template_dir = path;
+ *(strrchr(template_dir, '/') + 1) = '\0';
- template_path = strjoin(template_dir, template, NULL);
- if (!template_path) {
- free(path);
- free(template);
- return -ENOMEM;
- }
+ path = strappend(template_dir, template);
+ if (!path)
+ return -ENOMEM;
- /* Let's try to load template unit. */
- r = unit_file_load(c, info, template_path, allow_symlink);
- if (r >= 0) {
- info->path = strdup(template_path);
- if (!info->path) {
- free(path);
- free(template);
- free(template_path);
- return -ENOMEM;
- }
- }
+ if (!isempty(root_dir)) {
+ free(full_path);
+ full_path = strappend(root_dir, path);
+ if (!full_path)
+ return -ENOMEM;
+ }
- free(template);
- free(template_path);
+ /* Let's try to load template unit. */
+ r = unit_file_load(c, info, full_path ?: path, allow_symlink);
+ if (r >= 0) {
+ info->path = path;
+ path = NULL;
}
- free(path);
}
if (r != -ENOENT && r != -ELOOP)