path_simplify(p);
/* We remove all links pointing to a file or path that is marked, as well as all
- * files sharing the same name as a file that is marked. Do path chasing only if
- * we don't already know that we want to remove the symlink. */
+ * files sharing the same name as a file that is marked, and files sharing the same
+ * name after the instance has been removed. Do path chasing only if we don't already
+ * know that we want to remove the symlink. */
found = set_contains(remove_symlinks_to, de->d_name);
if (!found) {
- _cleanup_free_ char *dest = NULL;
+ _cleanup_free_ char *template = NULL;
+
+ q = unit_name_template(de->d_name, &template);
+ if (q < 0 && q != -EINVAL)
+ return q;
+ if (q >= 0)
+ found = set_contains(remove_symlinks_to, template);
+ }
+ if (!found) {
+ _cleanup_free_ char *dest = NULL;
q = chase_symlinks(p, lp->root_dir, CHASE_NONEXISTENT, &dest, NULL);
if (q == -ENOENT)
test ! -h "$root/etc/systemd/system/services.target.wants/templ1@two.service"
test ! -h "$root/etc/systemd/system/other@templ1.target.requires/templ1@two.service"
+: -------removal of relative enablement symlinks--------------
+test ! -h "$root/etc/systemd/system/services.target.wants/templ1@.service"
+ln -s '../templ1@one.service' "$root/etc/systemd/system/services.target.wants/templ1@one.service"
+ln -s 'templ1@two.service' "$root/etc/systemd/system/services.target.wants/templ1@two.service"
+ln -s '../templ1@.service' "$root/etc/systemd/system/services.target.wants/templ1@three.service"
+ln -s 'templ1@.service' "$root/etc/systemd/system/services.target.wants/templ1@four.service"
+ln -s '/usr/lib/systemd/system/templ1@.service' "$root/etc/systemd/system/services.target.wants/templ1@five.service"
+ln -s '/etc/systemd/system/templ1@.service' "$root/etc/systemd/system/services.target.wants/templ1@six.service"
+ln -s '/run/system/templ1@.service' "$root/etc/systemd/system/services.target.wants/templ1@seven.service"
+
+# this should remove all links
+"$systemctl" --root="$root" disable 'templ1@.service'
+test ! -h "$root/etc/systemd/system/services.target.wants/templ1@one.service"
+test ! -h "$root/etc/systemd/system/services.target.wants/templ1@two.service"
+test ! -h "$root/etc/systemd/system/services.target.wants/templ1@three.service"
+test ! -h "$root/etc/systemd/system/services.target.wants/templ1@four.service"
+test ! -h "$root/etc/systemd/system/services.target.wants/templ1@five.service"
+test ! -h "$root/etc/systemd/system/services.target.wants/templ1@six.service"
+test ! -h "$root/etc/systemd/system/services.target.wants/templ1@seven.service"
+
: -------template enablement for another template-------------
cat >"$root/etc/systemd/system/templ2@.service" <<EOF
[Install]