teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0488-install-small-refactor-to-combine-two-function-calls.patch

87d178
From eacb511fc0d1e3c5857cb041ad162fb78b4381cc Mon Sep 17 00:00:00 2001
87d178
From: Ruixin Bao <rubao@redhat.com>
87d178
Date: Sun, 26 Aug 2018 20:00:03 +0000
87d178
Subject: [PATCH] install: small refactor to combine two function calls into
87d178
 one function
87d178
87d178
Combine consecutive function calls of install_info_discover and
87d178
install_info_may_process into one short helper function.
87d178
87d178
(cherry picked from commit 1e475a0ab4c46eb07f3df3fb24f5a7c3e1fa20b1)
87d178
87d178
Related: #1812972
87d178
---
87d178
 src/shared/install.c | 61 ++++++++++++++++++++++----------------------
87d178
 1 file changed, 30 insertions(+), 31 deletions(-)
87d178
87d178
diff --git a/src/shared/install.c b/src/shared/install.c
87d178
index 1d4beaa83b..263b239f10 100644
87d178
--- a/src/shared/install.c
87d178
+++ b/src/shared/install.c
87d178
@@ -1676,6 +1676,25 @@ static int install_info_discover(
87d178
         return r;
87d178
 }
87d178
 
87d178
+static int install_info_discover_and_check(
87d178
+                        UnitFileScope scope,
87d178
+                        InstallContext *c,
87d178
+                        const LookupPaths *paths,
87d178
+                        const char *name,
87d178
+                        SearchFlags flags,
87d178
+                        UnitFileInstallInfo **ret,
87d178
+                        UnitFileChange **changes,
87d178
+                        size_t *n_changes) {
87d178
+
87d178
+        int r;
87d178
+
87d178
+        r = install_info_discover(scope, c, paths, name, flags, ret, changes, n_changes);
87d178
+        if (r < 0)
87d178
+                return r;
87d178
+
87d178
+        return install_info_may_process(ret ? *ret : NULL, paths, changes, n_changes);
87d178
+}
87d178
+
87d178
 static int install_info_symlink_alias(
87d178
                 UnitFileInstallInfo *i,
87d178
                 const LookupPaths *paths,
87d178
@@ -2399,11 +2418,8 @@ int unit_file_add_dependency(
87d178
         if (!config_path)
87d178
                 return -ENXIO;
87d178
 
87d178
-        r = install_info_discover(scope, &c, &paths, target, SEARCH_FOLLOW_CONFIG_SYMLINKS,
87d178
-                                  &target_info, changes, n_changes);
87d178
-        if (r < 0)
87d178
-                return r;
87d178
-        r = install_info_may_process(target_info, &paths, changes, n_changes);
87d178
+        r = install_info_discover_and_check(scope, &c, &paths, target, SEARCH_FOLLOW_CONFIG_SYMLINKS,
87d178
+                                            &target_info, changes, n_changes);
87d178
         if (r < 0)
87d178
                 return r;
87d178
 
87d178
@@ -2412,11 +2428,8 @@ int unit_file_add_dependency(
87d178
         STRV_FOREACH(f, files) {
87d178
                 char ***l;
87d178
 
87d178
-                r = install_info_discover(scope, &c, &paths, *f, SEARCH_FOLLOW_CONFIG_SYMLINKS,
87d178
-                                          &i, changes, n_changes);
87d178
-                if (r < 0)
87d178
-                        return r;
87d178
-                r = install_info_may_process(i, &paths, changes, n_changes);
87d178
+                r = install_info_discover_and_check(scope, &c, &paths, *f, SEARCH_FOLLOW_CONFIG_SYMLINKS,
87d178
+                                                    &i, changes, n_changes);
87d178
                 if (r < 0)
87d178
                         return r;
87d178
 
87d178
@@ -2467,11 +2480,8 @@ int unit_file_enable(
87d178
                 return -ENXIO;
87d178
 
87d178
         STRV_FOREACH(f, files) {
87d178
-                r = install_info_discover(scope, &c, &paths, *f, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS,
87d178
-                                          &i, changes, n_changes);
87d178
-                if (r < 0)
87d178
-                        return r;
87d178
-                r = install_info_may_process(i, &paths, changes, n_changes);
87d178
+                r = install_info_discover_and_check(scope, &c, &paths, *f, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS,
87d178
+                                                    &i, changes, n_changes);
87d178
                 if (r < 0)
87d178
                         return r;
87d178
 
87d178
@@ -2585,10 +2595,7 @@ int unit_file_set_default(
87d178
         if (r < 0)
87d178
                 return r;
87d178
 
87d178
-        r = install_info_discover(scope, &c, &paths, name, 0, &i, changes, n_changes);
87d178
-        if (r < 0)
87d178
-                return r;
87d178
-        r = install_info_may_process(i, &paths, changes, n_changes);
87d178
+        r = install_info_discover_and_check(scope, &c, &paths, name, 0, &i, changes, n_changes);
87d178
         if (r < 0)
87d178
                 return r;
87d178
 
87d178
@@ -3089,22 +3096,14 @@ static int preset_prepare_one(
87d178
                 if (instance_name_list) {
87d178
                         char **s;
87d178
                         STRV_FOREACH(s, instance_name_list) {
87d178
-                                r = install_info_discover(scope, plus, paths, *s, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS,
87d178
-                                                          &i, changes, n_changes);
87d178
-                                if (r < 0)
87d178
-                                        return r;
87d178
-
87d178
-                                r = install_info_may_process(i, paths, changes, n_changes);
87d178
+                                r = install_info_discover_and_check(scope, plus, paths, *s, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS,
87d178
+                                                                    &i, changes, n_changes);
87d178
                                 if (r < 0)
87d178
                                         return r;
87d178
                         }
87d178
                 } else {
87d178
-                        r = install_info_discover(scope, plus, paths, name, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS,
87d178
-                                                  &i, changes, n_changes);
87d178
-                        if (r < 0)
87d178
-                                return r;
87d178
-
87d178
-                        r = install_info_may_process(i, paths, changes, n_changes);
87d178
+                        r = install_info_discover_and_check(scope, plus, paths, name, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS,
87d178
+                                                            &i, changes, n_changes);
87d178
                         if (r < 0)
87d178
                                 return r;
87d178
                 }