696e2f2
From f0d72d47f05bbbb851d9ab64df877a3f0e769b4e Mon Sep 17 00:00:00 2001
696e2f2
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
696e2f2
Date: Sat, 13 Aug 2016 01:21:57 -0400
696e2f2
Subject: [PATCH] shared/install: move root skipping into create_symlink()
696e2f2
696e2f2
No functional change intended.
696e2f2
696e2f2
(cherry picked from commit 60bec8e4031367869520280350fa1523625d682b)
696e2f2
---
696e2f2
 src/shared/install.c | 33 +++++++++++++--------------------
696e2f2
 1 file changed, 13 insertions(+), 20 deletions(-)
696e2f2
696e2f2
diff --git a/src/shared/install.c b/src/shared/install.c
696e2f2
index ef5a56391c..8c45725f5a 100644
696e2f2
--- a/src/shared/install.c
696e2f2
+++ b/src/shared/install.c
696e2f2
@@ -394,6 +394,7 @@ void unit_file_dump_changes(int r, const char *verb, const UnitFileChange *chang
696e2f2
 }
696e2f2
 
696e2f2
 static int create_symlink(
696e2f2
+                const LookupPaths *paths,
696e2f2
                 const char *old_path,
696e2f2
                 const char *new_path,
696e2f2
                 bool force,
696e2f2
@@ -401,11 +402,16 @@ static int create_symlink(
696e2f2
                 unsigned *n_changes) {
696e2f2
 
696e2f2
         _cleanup_free_ char *dest = NULL;
696e2f2
+        const char *rp;
696e2f2
         int r;
696e2f2
 
696e2f2
         assert(old_path);
696e2f2
         assert(new_path);
696e2f2
 
696e2f2
+        rp = skip_root(paths, old_path);
696e2f2
+        if (rp)
696e2f2
+                old_path = rp;
696e2f2
+
696e2f2
         /* Actually create a symlink, and remember that we did. Is
696e2f2
          * smart enough to check if there's already a valid symlink in
696e2f2
          * place.
696e2f2
@@ -1486,7 +1492,6 @@ static int install_info_symlink_alias(
696e2f2
 
696e2f2
         STRV_FOREACH(s, i->aliases) {
696e2f2
                 _cleanup_free_ char *alias_path = NULL, *dst = NULL;
696e2f2
-                const char *rp;
696e2f2
 
696e2f2
                 q = install_full_printf(i, *s, &dst);
696e2f2
                 if (q < 0)
696e2f2
@@ -1496,9 +1501,7 @@ static int install_info_symlink_alias(
696e2f2
                 if (!alias_path)
696e2f2
                         return -ENOMEM;
696e2f2
 
696e2f2
-                rp = skip_root(paths, i->path);
696e2f2
-
696e2f2
-                q = create_symlink(rp ?: i->path, alias_path, force, changes, n_changes);
696e2f2
+                q = create_symlink(paths, i->path, alias_path, force, changes, n_changes);
696e2f2
                 if (r == 0)
696e2f2
                         r = q;
696e2f2
         }
696e2f2
@@ -1542,7 +1545,6 @@ static int install_info_symlink_wants(
696e2f2
 
696e2f2
         STRV_FOREACH(s, list) {
696e2f2
                 _cleanup_free_ char *path = NULL, *dst = NULL;
696e2f2
-                const char *rp;
696e2f2
 
696e2f2
                 q = install_full_printf(i, *s, &dst);
696e2f2
                 if (q < 0)
696e2f2
@@ -1557,9 +1559,7 @@ static int install_info_symlink_wants(
696e2f2
                 if (!path)
696e2f2
                         return -ENOMEM;
696e2f2
 
696e2f2
-                rp = skip_root(paths, i->path);
696e2f2
-
696e2f2
-                q = create_symlink(rp ?: i->path, path, true, changes, n_changes);
696e2f2
+                q = create_symlink(paths, i->path, path, true, changes, n_changes);
696e2f2
                 if (r == 0)
696e2f2
                         r = q;
696e2f2
         }
696e2f2
@@ -1576,7 +1576,6 @@ static int install_info_symlink_link(
696e2f2
                 unsigned *n_changes) {
696e2f2
 
696e2f2
         _cleanup_free_ char *path = NULL;
696e2f2
-        const char *rp;
696e2f2
         int r;
696e2f2
 
696e2f2
         assert(i);
696e2f2
@@ -1594,9 +1593,7 @@ static int install_info_symlink_link(
696e2f2
         if (!path)
696e2f2
                 return -ENOMEM;
696e2f2
 
696e2f2
-        rp = skip_root(paths, i->path);
696e2f2
-
696e2f2
-        return create_symlink(rp ?: i->path, path, force, changes, n_changes);
696e2f2
+        return create_symlink(paths, i->path, path, force, changes, n_changes);
696e2f2
 }
696e2f2
 
696e2f2
 static int install_info_apply(
696e2f2
@@ -1772,7 +1769,7 @@ int unit_file_mask(
696e2f2
                 if (!path)
696e2f2
                         return -ENOMEM;
696e2f2
 
696e2f2
-                q = create_symlink("/dev/null", path, force, changes, n_changes);
696e2f2
+                q = create_symlink(&paths, "/dev/null", path, force, changes, n_changes);
696e2f2
                 if (q < 0 && r >= 0)
696e2f2
                         r = q;
696e2f2
         }
696e2f2
@@ -1932,14 +1929,12 @@ int unit_file_link(
696e2f2
         r = 0;
696e2f2
         STRV_FOREACH(i, todo) {
696e2f2
                 _cleanup_free_ char *new_path = NULL;
696e2f2
-                const char *old_path;
696e2f2
 
696e2f2
-                old_path = skip_root(&paths, *i);
696e2f2
                 new_path = path_make_absolute(basename(*i), config_path);
696e2f2
                 if (!new_path)
696e2f2
                         return -ENOMEM;
696e2f2
 
696e2f2
-                q = create_symlink(old_path ?: *i, new_path, force, changes, n_changes);
696e2f2
+                q = create_symlink(&paths, *i, new_path, force, changes, n_changes);
696e2f2
                 if (q < 0 && r >= 0)
696e2f2
                         r = q;
696e2f2
         }
696e2f2
@@ -2318,7 +2313,7 @@ int unit_file_set_default(
696e2f2
         _cleanup_lookup_paths_free_ LookupPaths paths = {};
696e2f2
         _cleanup_(install_context_done) InstallContext c = {};
696e2f2
         UnitFileInstallInfo *i;
696e2f2
-        const char *new_path, *old_path;
696e2f2
+        const char *new_path;
696e2f2
         int r;
696e2f2
 
696e2f2
         assert(scope >= 0);
696e2f2
@@ -2341,10 +2336,8 @@ int unit_file_set_default(
696e2f2
         if (r < 0)
696e2f2
                 return r;
696e2f2
 
696e2f2
-        old_path = skip_root(&paths, i->path);
696e2f2
         new_path = strjoina(paths.persistent_config, "/" SPECIAL_DEFAULT_TARGET);
696e2f2
-
696e2f2
-        return create_symlink(old_path ?: i->path, new_path, force, changes, n_changes);
696e2f2
+        return create_symlink(&paths, i->path, new_path, force, changes, n_changes);
696e2f2
 }
696e2f2
 
696e2f2
 int unit_file_get_default(