dryang / rpms / systemd

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