5509c00
From 90d16404421d61e4e13bcff35f914477b9d04d81 Mon Sep 17 00:00:00 2001
5509c00
From: Lennart Poettering <lennart@poettering.net>
5509c00
Date: Tue, 17 Jun 2014 00:33:39 +0200
5509c00
Subject: [PATCH] install: make sure "systemctl disable foobar@.service"
5509c00
 actually removes all instances
5509c00
5509c00
(cherry picked from commit 559367add5e22bf32d14fa1496512c68488f48b0)
5509c00
---
5509c00
 src/shared/install.c | 24 +++++++++++++++++-------
5509c00
 1 file changed, 17 insertions(+), 7 deletions(-)
5509c00
5509c00
diff --git a/src/shared/install.c b/src/shared/install.c
5509c00
index e16de4d6..278350be 100644
5509c00
--- a/src/shared/install.c
5509c00
+++ b/src/shared/install.c
5509c00
@@ -266,8 +266,22 @@ static int remove_marked_symlinks_fd(
5509c00
 
5509c00
                         if (unit_name_is_instance(de->d_name) &&
5509c00
                             instance_whitelist &&
5509c00
-                            !strv_contains(instance_whitelist, de->d_name))
5509c00
-                                continue;
5509c00
+                            !strv_contains(instance_whitelist, de->d_name)) {
5509c00
+
5509c00
+                                _cleanup_free_ char *w;
5509c00
+
5509c00
+                                /* OK, the file is not listed directly
5509c00
+                                 * in the whitelist, so let's check if
5509c00
+                                 * the template of it might be
5509c00
+                                 * listed. */
5509c00
+
5509c00
+                                w = unit_name_template(de->d_name);
5509c00
+                                if (!w)
5509c00
+                                        return -ENOMEM;
5509c00
+
5509c00
+                                if (!strv_contains(instance_whitelist, w))
5509c00
+                                        continue;
5509c00
+                        }
5509c00
 
5509c00
                         p = path_make_absolute(de->d_name, path);
5509c00
                         if (!p)
5509c00
@@ -290,18 +304,14 @@ static int remove_marked_symlinks_fd(
5509c00
                         if (!found)
5509c00
                                 continue;
5509c00
 
5509c00
-
5509c00
                         if (unlink(p) < 0 && errno != ENOENT) {
5509c00
-
5509c00
                                 if (r == 0)
5509c00
                                         r = -errno;
5509c00
                                 continue;
5509c00
                         }
5509c00
 
5509c00
-                        rmdir_parents(p, config_path);
5509c00
-
5509c00
                         path_kill_slashes(p);
5509c00
-
5509c00
+                        rmdir_parents(p, config_path);
5509c00
                         add_file_change(changes, n_changes, UNIT_FILE_UNLINK, p, NULL);
5509c00
 
5509c00
                         if (!set_get(remove_symlinks_to, p)) {