5509c00
From bf160761cd5d35458779e96fa13655dd88350ccd Mon Sep 17 00:00:00 2001
5509c00
From: Lennart Poettering <lennart@poettering.net>
5509c00
Date: Mon, 16 Jun 2014 19:48:31 +0200
5509c00
Subject: [PATCH] install: simplify and clarify disabling logic for instanced
5509c00
 units
5509c00
5509c00
(cherry picked from commit bcafe923a74e702abbba3655b0270febe143499f)
5509c00
---
5509c00
 src/shared/install.c | 50 ++++++++++++++++++++++++++++----------------------
5509c00
 1 file changed, 28 insertions(+), 22 deletions(-)
5509c00
5509c00
diff --git a/src/shared/install.c b/src/shared/install.c
5509c00
index 115d831d..40dc7beb 100644
5509c00
--- a/src/shared/install.c
5509c00
+++ b/src/shared/install.c
5509c00
@@ -194,10 +194,10 @@ static int remove_marked_symlinks_fd(
5509c00
                 bool *deleted,
5509c00
                 UnitFileChange **changes,
5509c00
                 unsigned *n_changes,
5509c00
-                char** files) {
5509c00
+                char** instance_whitelist) {
5509c00
 
5509c00
-        int r = 0;
5509c00
         _cleanup_closedir_ DIR *d = NULL;
5509c00
+        int r = 0;
5509c00
 
5509c00
         assert(remove_symlinks_to);
5509c00
         assert(fd >= 0);
5509c00
@@ -252,9 +252,8 @@ static int remove_marked_symlinks_fd(
5509c00
                         }
5509c00
 
5509c00
                         /* This will close nfd, regardless whether it succeeds or not */
5509c00
-                        q = remove_marked_symlinks_fd(remove_symlinks_to, nfd, p, config_path, deleted, changes, n_changes, files);
5509c00
-
5509c00
-                        if (r == 0)
5509c00
+                        q = remove_marked_symlinks_fd(remove_symlinks_to, nfd, p, config_path, deleted, changes, n_changes, instance_whitelist);
5509c00
+                        if (q < 0 && r == 0)
5509c00
                                 r = q;
5509c00
 
5509c00
                 } else if (de->d_type == DT_LNK) {
5509c00
@@ -262,6 +261,14 @@ static int remove_marked_symlinks_fd(
5509c00
                         int q;
5509c00
                         bool found;
5509c00
 
5509c00
+                        if (!unit_name_is_valid(de->d_name, TEMPLATE_VALID))
5509c00
+                                continue;
5509c00
+
5509c00
+                        if (unit_name_is_instance(de->d_name) &&
5509c00
+                            instance_whitelist &&
5509c00
+                            !strv_contains(instance_whitelist, de->d_name))
5509c00
+                                continue;
5509c00
+
5509c00
                         p = path_make_absolute(de->d_name, path);
5509c00
                         if (!p)
5509c00
                                 return -ENOMEM;
5509c00
@@ -280,30 +287,29 @@ static int remove_marked_symlinks_fd(
5509c00
                                 set_get(remove_symlinks_to, dest) ||
5509c00
                                 set_get(remove_symlinks_to, basename(dest));
5509c00
 
5509c00
-                        if (unit_name_is_instance(p))
5509c00
-                                found = found && strv_contains(files, basename(p));
5509c00
-
5509c00
                         if (found) {
5509c00
 
5509c00
                                 if (unlink(p) < 0 && errno != ENOENT) {
5509c00
 
5509c00
                                         if (r == 0)
5509c00
                                                 r = -errno;
5509c00
-                                } else {
5509c00
-                                        rmdir_parents(p, config_path);
5509c00
-                                        path_kill_slashes(p);
5509c00
+                                        continue;
5509c00
+                                }
5509c00
+
5509c00
+                                rmdir_parents(p, config_path);
5509c00
+
5509c00
+                                path_kill_slashes(p);
5509c00
 
5509c00
-                                        add_file_change(changes, n_changes, UNIT_FILE_UNLINK, p, NULL);
5509c00
+                                add_file_change(changes, n_changes, UNIT_FILE_UNLINK, p, NULL);
5509c00
 
5509c00
-                                        if (!set_get(remove_symlinks_to, p)) {
5509c00
+                                if (!set_get(remove_symlinks_to, p)) {
5509c00
 
5509c00
-                                                q = mark_symlink_for_removal(&remove_symlinks_to, p);
5509c00
-                                                if (q < 0) {
5509c00
-                                                        if (r == 0)
5509c00
-                                                                r = q;
5509c00
-                                                } else
5509c00
-                                                        *deleted = true;
5509c00
-                                        }
5509c00
+                                        q = mark_symlink_for_removal(&remove_symlinks_to, p);
5509c00
+                                        if (q < 0) {
5509c00
+                                                if (r == 0)
5509c00
+                                                        r = q;
5509c00
+                                        } else
5509c00
+                                                *deleted = true;
5509c00
                                 }
5509c00
                         }
5509c00
                 }
5509c00
@@ -317,7 +323,7 @@ static int remove_marked_symlinks(
5509c00
                 const char *config_path,
5509c00
                 UnitFileChange **changes,
5509c00
                 unsigned *n_changes,
5509c00
-                char** files) {
5509c00
+                char** instance_whitelist) {
5509c00
 
5509c00
         _cleanup_close_ int fd = -1;
5509c00
         int r = 0;
5509c00
@@ -343,7 +349,7 @@ static int remove_marked_symlinks(
5509c00
                 }
5509c00
 
5509c00
                 /* This takes possession of cfd and closes it */
5509c00
-                q = remove_marked_symlinks_fd(remove_symlinks_to, cfd, config_path, config_path, &deleted, changes, n_changes, files);
5509c00
+                q = remove_marked_symlinks_fd(remove_symlinks_to, cfd, config_path, config_path, &deleted, changes, n_changes, instance_whitelist);
5509c00
                 if (r == 0)
5509c00
                         r = q;
5509c00
         } while (deleted);