richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
923a60
From f8fd91c9f0f1f7feabf8567bdad61f57fe922011 Mon Sep 17 00:00:00 2001
923a60
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
923a60
Date: Sat, 14 Mar 2015 21:46:59 -0400
923a60
Subject: [PATCH] sysv-generator: initialize LookupPaths just once
923a60
923a60
With debugging on, sysv-generator would print the full set of
923a60
lookup paths for *every* sysv script.
923a60
923a60
While at it, pass LookupPaths as a pointer in sysv-generator,
923a60
and constify it everywhere.
923a60
923a60
(cherry picked from commit a8ffe6fbcbfdba39aef8dce8b298b3e0cb377c0e)
923a60
---
923a60
 src/shared/install.c                | 55 +++++++++++++++++------------
923a60
 src/shared/install.h                | 11 +++++-
923a60
 src/shared/path-lookup.c            |  1 +
923a60
 src/shared/path-lookup.h            |  3 +-
923a60
 src/sysv-generator/sysv-generator.c | 14 ++++----
923a60
 5 files changed, 53 insertions(+), 31 deletions(-)
923a60
923a60
diff --git a/src/shared/install.c b/src/shared/install.c
923a60
index 65f1c245c6..92b8d6e8ef 100644
923a60
--- a/src/shared/install.c
923a60
+++ b/src/shared/install.c
923a60
@@ -1084,7 +1084,7 @@ static int unit_file_load(
923a60
 static int unit_file_search(
923a60
                 InstallContext *c,
923a60
                 InstallInfo *info,
923a60
-                LookupPaths *paths,
923a60
+                const LookupPaths *paths,
923a60
                 const char *root_dir,
923a60
                 bool allow_symlink,
923a60
                 bool load,
923a60
@@ -1153,7 +1153,7 @@ static int unit_file_search(
923a60
 }
923a60
 
923a60
 static int unit_file_can_install(
923a60
-                LookupPaths *paths,
923a60
+                const LookupPaths *paths,
923a60
                 const char *root_dir,
923a60
                 const char *name,
923a60
                 bool allow_symlink,
923a60
@@ -1317,7 +1317,7 @@ static int install_info_symlink_wants(
923a60
 
923a60
 static int install_info_symlink_link(
923a60
                 InstallInfo *i,
923a60
-                LookupPaths *paths,
923a60
+                const LookupPaths *paths,
923a60
                 const char *config_path,
923a60
                 const char *root_dir,
923a60
                 bool force,
923a60
@@ -1345,7 +1345,7 @@ static int install_info_symlink_link(
923a60
 
923a60
 static int install_info_apply(
923a60
                 InstallInfo *i,
923a60
-                LookupPaths *paths,
923a60
+                const LookupPaths *paths,
923a60
                 const char *config_path,
923a60
                 const char *root_dir,
923a60
                 bool force,
923a60
@@ -1377,7 +1377,7 @@ static int install_info_apply(
923a60
 
923a60
 static int install_context_apply(
923a60
                 InstallContext *c,
923a60
-                LookupPaths *paths,
923a60
+                const LookupPaths *paths,
923a60
                 const char *config_path,
923a60
                 const char *root_dir,
923a60
                 bool force,
923a60
@@ -1424,7 +1424,7 @@ static int install_context_apply(
923a60
 
923a60
 static int install_context_mark_for_removal(
923a60
                 InstallContext *c,
923a60
-                LookupPaths *paths,
923a60
+                const LookupPaths *paths,
923a60
                 Set **remove_symlinks_to,
923a60
                 const char *config_path,
923a60
                 const char *root_dir) {
923a60
@@ -1785,39 +1785,28 @@ int unit_file_get_default(
923a60
         return -ENOENT;
923a60
 }
923a60
 
923a60
-UnitFileState unit_file_get_state(
923a60
+UnitFileState unit_file_lookup_state(
923a60
                 UnitFileScope scope,
923a60
                 const char *root_dir,
923a60
+                const LookupPaths *paths,
923a60
                 const char *name) {
923a60
 
923a60
-        _cleanup_lookup_paths_free_ LookupPaths paths = {};
923a60
         UnitFileState state = _UNIT_FILE_STATE_INVALID;
923a60
         char **i;
923a60
         _cleanup_free_ char *path = NULL;
923a60
         int r;
923a60
 
923a60
-        assert(scope >= 0);
923a60
-        assert(scope < _UNIT_FILE_SCOPE_MAX);
923a60
-        assert(name);
923a60
-
923a60
-        if (root_dir && scope != UNIT_FILE_SYSTEM)
923a60
-                return -EINVAL;
923a60
+        assert(paths);
923a60
 
923a60
         if (!unit_name_is_valid(name, TEMPLATE_VALID))
923a60
                 return -EINVAL;
923a60
 
923a60
-        r = lookup_paths_init_from_scope(&paths, scope, root_dir);
923a60
-        if (r < 0)
923a60
-                return r;
923a60
-
923a60
-        STRV_FOREACH(i, paths.unit_path) {
923a60
+        STRV_FOREACH(i, paths->unit_path) {
923a60
                 struct stat st;
923a60
                 char *partial;
923a60
                 bool also = false;
923a60
 
923a60
                 free(path);
923a60
-                path = NULL;
923a60
-
923a60
                 path = path_join(root_dir, *i, name);
923a60
                 if (!path)
923a60
                         return -ENOMEM;
923a60
@@ -1858,7 +1847,7 @@ UnitFileState unit_file_get_state(
923a60
                 else if (r > 0)
923a60
                         return state;
923a60
 
923a60
-                r = unit_file_can_install(&paths, root_dir, partial, true, &also);
923a60
+                r = unit_file_can_install(paths, root_dir, partial, true, &also);
923a60
                 if (r < 0 && errno != ENOENT)
923a60
                         return r;
923a60
                 else if (r > 0)
923a60
@@ -1873,6 +1862,28 @@ UnitFileState unit_file_get_state(
923a60
         return r < 0 ? r : state;
923a60
 }
923a60
 
923a60
+UnitFileState unit_file_get_state(
923a60
+                UnitFileScope scope,
923a60
+                const char *root_dir,
923a60
+                const char *name) {
923a60
+
923a60
+        _cleanup_lookup_paths_free_ LookupPaths paths = {};
923a60
+        int r;
923a60
+
923a60
+        assert(scope >= 0);
923a60
+        assert(scope < _UNIT_FILE_SCOPE_MAX);
923a60
+        assert(name);
923a60
+
923a60
+        if (root_dir && scope != UNIT_FILE_SYSTEM)
923a60
+                return -EINVAL;
923a60
+
923a60
+        r = lookup_paths_init_from_scope(&paths, scope, root_dir);
923a60
+        if (r < 0)
923a60
+                return r;
923a60
+
923a60
+        return unit_file_lookup_state(scope, root_dir, &paths, name);
923a60
+}
923a60
+
923a60
 int unit_file_query_preset(UnitFileScope scope, const char *root_dir, const char *name) {
923a60
         _cleanup_strv_free_ char **files = NULL;
923a60
         char **p;
923a60
diff --git a/src/shared/install.h b/src/shared/install.h
923a60
index 357be0f92d..3ca39397e6 100644
923a60
--- a/src/shared/install.h
923a60
+++ b/src/shared/install.h
923a60
@@ -23,6 +23,7 @@
923a60
 
923a60
 #include "hashmap.h"
923a60
 #include "unit-name.h"
923a60
+#include "path-lookup.h"
923a60
 
923a60
 typedef enum UnitFileScope {
923a60
         UNIT_FILE_SYSTEM,
923a60
@@ -98,7 +99,15 @@ int unit_file_set_default(UnitFileScope scope, const char *root_dir, const char
923a60
 int unit_file_get_default(UnitFileScope scope, const char *root_dir, char **name);
923a60
 int unit_file_add_dependency(UnitFileScope scope, bool runtime, const char *root_dir, char **files, char *target, UnitDependency dep, bool force, UnitFileChange **changes, unsigned *n_changes);
923a60
 
923a60
-UnitFileState unit_file_get_state(UnitFileScope scope, const char *root_dir, const char *filename);
923a60
+UnitFileState unit_file_lookup_state(
923a60
+                UnitFileScope scope,
923a60
+                const char *root_dir,
923a60
+                const LookupPaths *paths,
923a60
+                const char *name);
923a60
+UnitFileState unit_file_get_state(
923a60
+                UnitFileScope scope,
923a60
+                const char *root_dir,
923a60
+                const char *filename);
923a60
 
923a60
 int unit_file_get_list(UnitFileScope scope, const char *root_dir, Hashmap *h);
923a60
 
923a60
diff --git a/src/shared/path-lookup.c b/src/shared/path-lookup.c
923a60
index 291a2f4054..812730be1c 100644
923a60
--- a/src/shared/path-lookup.c
923a60
+++ b/src/shared/path-lookup.c
923a60
@@ -31,6 +31,7 @@
923a60
 #include "strv.h"
923a60
 #include "path-util.h"
923a60
 #include "path-lookup.h"
923a60
+#include "install.h"
923a60
 
923a60
 int user_config_home(char **config_home) {
923a60
         const char *e;
923a60
diff --git a/src/shared/path-lookup.h b/src/shared/path-lookup.h
923a60
index 2ec888da81..f1925eef69 100644
923a60
--- a/src/shared/path-lookup.h
923a60
+++ b/src/shared/path-lookup.h
923a60
@@ -22,7 +22,8 @@
923a60
 ***/
923a60
 
923a60
 #include "macro.h"
923a60
-#include "install.h"
923a60
+
923a60
+typedef enum UnitFileScope UnitFileScope;
923a60
 
923a60
 typedef struct LookupPaths {
923a60
         char **unit_path;
923a60
diff --git a/src/sysv-generator/sysv-generator.c b/src/sysv-generator/sysv-generator.c
923a60
index 6e39b449eb..0125ca27d9 100644
923a60
--- a/src/sysv-generator/sysv-generator.c
923a60
+++ b/src/sysv-generator/sysv-generator.c
923a60
@@ -723,10 +723,10 @@ static int fix_order(SysvStub *s, Hashmap *all_services) {
923a60
         return 0;
923a60
 }
923a60
 
923a60
-static int enumerate_sysv(LookupPaths lp, Hashmap *all_services) {
923a60
+static int enumerate_sysv(const LookupPaths *lp, Hashmap *all_services) {
923a60
         char **path;
923a60
 
923a60
-        STRV_FOREACH(path, lp.sysvinit_path) {
923a60
+        STRV_FOREACH(path, lp->sysvinit_path) {
923a60
                 _cleanup_closedir_ DIR *d = NULL;
923a60
                 struct dirent *de;
923a60
 
923a60
@@ -768,7 +768,7 @@ static int enumerate_sysv(LookupPaths lp, Hashmap *all_services) {
923a60
                         if (!fpath)
923a60
                                 return log_oom();
923a60
 
923a60
-                        if (unit_file_get_state(UNIT_FILE_SYSTEM, NULL, name) >= 0) {
923a60
+                        if (unit_file_lookup_state(UNIT_FILE_SYSTEM, NULL, lp, name) >= 0) {
923a60
                                 log_debug("Native unit for %s already exists, skipping", name);
923a60
                                 continue;
923a60
                         }
923a60
@@ -793,7 +793,7 @@ static int enumerate_sysv(LookupPaths lp, Hashmap *all_services) {
923a60
         return 0;
923a60
 }
923a60
 
923a60
-static int set_dependencies_from_rcnd(LookupPaths lp, Hashmap *all_services) {
923a60
+static int set_dependencies_from_rcnd(const LookupPaths *lp, Hashmap *all_services) {
923a60
         char **p;
923a60
         unsigned i;
923a60
         _cleanup_closedir_ DIR *d = NULL;
923a60
@@ -804,7 +804,7 @@ static int set_dependencies_from_rcnd(LookupPaths lp, Hashmap *all_services) {
923a60
         _cleanup_set_free_ Set *shutdown_services = NULL;
923a60
         int r = 0;
923a60
 
923a60
-        STRV_FOREACH(p, lp.sysvrcnd_path)
923a60
+        STRV_FOREACH(p, lp->sysvrcnd_path)
923a60
                 for (i = 0; i < ELEMENTSOF(rcnd_table); i ++) {
923a60
                         struct dirent *de;
923a60
 
923a60
@@ -954,13 +954,13 @@ int main(int argc, char *argv[]) {
923a60
                 return EXIT_FAILURE;
923a60
         }
923a60
 
923a60
-        r = enumerate_sysv(lp, all_services);
923a60
+        r = enumerate_sysv(&lp, all_services);
923a60
         if (r < 0) {
923a60
                 log_error("Failed to generate units for all init scripts.");
923a60
                 return EXIT_FAILURE;
923a60
         }
923a60
 
923a60
-        r = set_dependencies_from_rcnd(lp, all_services);
923a60
+        r = set_dependencies_from_rcnd(&lp, all_services);
923a60
         if (r < 0) {
923a60
                 log_error("Failed to read runlevels from rcnd links.");
923a60
                 return EXIT_FAILURE;