]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/unit-file: fix resolution of absoulute symlinks with --root
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 30 Apr 2020 10:02:44 +0000 (12:02 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 30 Apr 2020 10:02:44 +0000 (12:02 +0200)
$ systemctl --no-pager --root /tmp/root2/ cat ctrl-alt-del.target
Failed to resolve symlink /tmp/root2/etc/systemd/system/ctrl-alt-del.target pointing to /usr/lib/systemd/system/reboot.target, ignoring: Channel number out of range
...

src/shared/unit-file.c

index 7ad0ecc8fdca4f340d6b38bb339e81cd57e541a2..7b64bbf7f1b68ea282dd8ddc70536a2aa6ebf3f3 100644 (file)
@@ -320,7 +320,7 @@ int unit_file_build_name_map(
                                 /* We don't explicitly check for alias loops here. unit_ids_map_get() which
                                  * limits the number of hops should be used to access the map. */
 
-                                _cleanup_free_ char *target = NULL, *target_abs = NULL;
+                                _cleanup_free_ char *target = NULL;
 
                                 r = readlinkat_malloc(dirfd(d), de->d_name, &target);
                                 if (r < 0) {
@@ -329,8 +329,9 @@ int unit_file_build_name_map(
                                         continue;
                                 }
 
-                                if (!path_is_absolute(target)) {
-                                        target_abs = path_join(*dir, target);
+                                const bool is_abs = path_is_absolute(target);
+                                if (lp->root_dir || !is_abs) {
+                                        char *target_abs = path_join(is_abs ? lp->root_dir : *dir, target);
                                         if (!target_abs)
                                                 return log_oom();