chiark / gitweb /
sysv-generator: initialize LookupPaths just once
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 15 Mar 2015 01:46:59 +0000 (21:46 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 15 Mar 2015 03:03:21 +0000 (23:03 -0400)
With debugging on, sysv-generator would print the full set of
lookup paths for *every* sysv script.

While at it, pass LookupPaths as a pointer in sysv-generator,
and constify it everywhere.

src/shared/install.c
src/shared/install.h
src/shared/path-lookup.c
src/shared/path-lookup.h
src/sysv-generator/sysv-generator.c

index 7a7ec19f32e9df268d3121db1f287208396b2a9c..9c680a761b262bff0498298006d808660afb3ce5 100644 (file)
@@ -1083,7 +1083,7 @@ static int unit_file_load(
 static int unit_file_search(
                 InstallContext *c,
                 InstallInfo *info,
-                LookupPaths *paths,
+                const LookupPaths *paths,
                 const char *root_dir,
                 bool allow_symlink,
                 bool load,
@@ -1152,7 +1152,7 @@ static int unit_file_search(
 }
 
 static int unit_file_can_install(
-                LookupPaths *paths,
+                const LookupPaths *paths,
                 const char *root_dir,
                 const char *name,
                 bool allow_symlink,
@@ -1316,7 +1316,7 @@ static int install_info_symlink_wants(
 
 static int install_info_symlink_link(
                 InstallInfo *i,
-                LookupPaths *paths,
+                const LookupPaths *paths,
                 const char *config_path,
                 const char *root_dir,
                 bool force,
@@ -1344,7 +1344,7 @@ static int install_info_symlink_link(
 
 static int install_info_apply(
                 InstallInfo *i,
-                LookupPaths *paths,
+                const LookupPaths *paths,
                 const char *config_path,
                 const char *root_dir,
                 bool force,
@@ -1376,7 +1376,7 @@ static int install_info_apply(
 
 static int install_context_apply(
                 InstallContext *c,
-                LookupPaths *paths,
+                const LookupPaths *paths,
                 const char *config_path,
                 const char *root_dir,
                 bool force,
@@ -1423,7 +1423,7 @@ static int install_context_apply(
 
 static int install_context_mark_for_removal(
                 InstallContext *c,
-                LookupPaths *paths,
+                const LookupPaths *paths,
                 Set **remove_symlinks_to,
                 const char *config_path,
                 const char *root_dir) {
@@ -1784,39 +1784,28 @@ int unit_file_get_default(
         return -ENOENT;
 }
 
-UnitFileState unit_file_get_state(
+UnitFileState unit_file_lookup_state(
                 UnitFileScope scope,
                 const char *root_dir,
+                const LookupPaths *paths,
                 const char *name) {
 
-        _cleanup_lookup_paths_free_ LookupPaths paths = {};
         UnitFileState state = _UNIT_FILE_STATE_INVALID;
         char **i;
         _cleanup_free_ char *path = NULL;
         int r;
 
-        assert(scope >= 0);
-        assert(scope < _UNIT_FILE_SCOPE_MAX);
-        assert(name);
-
-        if (root_dir && scope != UNIT_FILE_SYSTEM)
-                return -EINVAL;
+        assert(paths);
 
         if (!unit_name_is_valid(name, TEMPLATE_VALID))
                 return -EINVAL;
 
-        r = lookup_paths_init_from_scope(&paths, scope, root_dir);
-        if (r < 0)
-                return r;
-
-        STRV_FOREACH(i, paths.unit_path) {
+        STRV_FOREACH(i, paths->unit_path) {
                 struct stat st;
                 char *partial;
                 bool also = false;
 
                 free(path);
-                path = NULL;
-
                 path = path_join(root_dir, *i, name);
                 if (!path)
                         return -ENOMEM;
@@ -1857,7 +1846,7 @@ UnitFileState unit_file_get_state(
                 else if (r > 0)
                         return state;
 
-                r = unit_file_can_install(&paths, root_dir, partial, true, &also);
+                r = unit_file_can_install(paths, root_dir, partial, true, &also);
                 if (r < 0 && errno != ENOENT)
                         return r;
                 else if (r > 0)
@@ -1872,6 +1861,28 @@ UnitFileState unit_file_get_state(
         return r < 0 ? r : state;
 }
 
+UnitFileState unit_file_get_state(
+                UnitFileScope scope,
+                const char *root_dir,
+                const char *name) {
+
+        _cleanup_lookup_paths_free_ LookupPaths paths = {};
+        int r;
+
+        assert(scope >= 0);
+        assert(scope < _UNIT_FILE_SCOPE_MAX);
+        assert(name);
+
+        if (root_dir && scope != UNIT_FILE_SYSTEM)
+                return -EINVAL;
+
+        r = lookup_paths_init_from_scope(&paths, scope, root_dir);
+        if (r < 0)
+                return r;
+
+        return unit_file_lookup_state(scope, root_dir, &paths, name);
+}
+
 int unit_file_query_preset(UnitFileScope scope, const char *root_dir, const char *name) {
         _cleanup_strv_free_ char **files = NULL;
         char **p;
index 357be0f92d9b6ca7e29d42ee6083e5cd1fb1f493..3ca39397e6fef10c610dc54da5cd5efa9413aebb 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "hashmap.h"
 #include "unit-name.h"
+#include "path-lookup.h"
 
 typedef enum UnitFileScope {
         UNIT_FILE_SYSTEM,
@@ -98,7 +99,15 @@ int unit_file_set_default(UnitFileScope scope, const char *root_dir, const char
 int unit_file_get_default(UnitFileScope scope, const char *root_dir, char **name);
 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);
 
-UnitFileState unit_file_get_state(UnitFileScope scope, const char *root_dir, const char *filename);
+UnitFileState unit_file_lookup_state(
+                UnitFileScope scope,
+                const char *root_dir,
+                const LookupPaths *paths,
+                const char *name);
+UnitFileState unit_file_get_state(
+                UnitFileScope scope,
+                const char *root_dir,
+                const char *filename);
 
 int unit_file_get_list(UnitFileScope scope, const char *root_dir, Hashmap *h);
 
index fbf46cd40690acee9cd336a508701d69dc2a8075..fb2c2c233a0d86c7c0814368762ae3e3f41708a5 100644 (file)
@@ -28,6 +28,7 @@
 #include "strv.h"
 #include "path-util.h"
 #include "path-lookup.h"
+#include "install.h"
 
 int user_config_home(char **config_home) {
         const char *e;
index 2ec888da811d0981cc5b41ccc4648a9b8e7d2d30..f1925eef69c17a7a8538f6d8d46f6a12c185b4cf 100644 (file)
@@ -22,7 +22,8 @@
 ***/
 
 #include "macro.h"
-#include "install.h"
+
+typedef enum UnitFileScope UnitFileScope;
 
 typedef struct LookupPaths {
         char **unit_path;
index 25b10c1a49bb5c3cb731b17f3cc926f17243d160..4beea4dd02ed9a4d4332166713680d34e1ff86db 100644 (file)
@@ -719,10 +719,10 @@ static int fix_order(SysvStub *s, Hashmap *all_services) {
         return 0;
 }
 
-static int enumerate_sysv(LookupPaths lp, Hashmap *all_services) {
+static int enumerate_sysv(const LookupPaths *lp, Hashmap *all_services) {
         char **path;
 
-        STRV_FOREACH(path, lp.sysvinit_path) {
+        STRV_FOREACH(path, lp->sysvinit_path) {
                 _cleanup_closedir_ DIR *d = NULL;
                 struct dirent *de;
 
@@ -764,7 +764,7 @@ static int enumerate_sysv(LookupPaths lp, Hashmap *all_services) {
                         if (!fpath)
                                 return log_oom();
 
-                        if (unit_file_get_state(UNIT_FILE_SYSTEM, NULL, name) >= 0) {
+                        if (unit_file_lookup_state(UNIT_FILE_SYSTEM, NULL, lp, name) >= 0) {
                                 log_debug("Native unit for %s already exists, skipping", name);
                                 continue;
                         }
@@ -789,7 +789,7 @@ static int enumerate_sysv(LookupPaths lp, Hashmap *all_services) {
         return 0;
 }
 
-static int set_dependencies_from_rcnd(LookupPaths lp, Hashmap *all_services) {
+static int set_dependencies_from_rcnd(const LookupPaths *lp, Hashmap *all_services) {
         char **p;
         unsigned i;
         _cleanup_closedir_ DIR *d = NULL;
@@ -800,7 +800,7 @@ static int set_dependencies_from_rcnd(LookupPaths lp, Hashmap *all_services) {
         _cleanup_set_free_ Set *shutdown_services = NULL;
         int r = 0;
 
-        STRV_FOREACH(p, lp.sysvrcnd_path)
+        STRV_FOREACH(p, lp->sysvrcnd_path)
                 for (i = 0; i < ELEMENTSOF(rcnd_table); i ++) {
                         struct dirent *de;
 
@@ -950,13 +950,13 @@ int main(int argc, char *argv[]) {
                 return EXIT_FAILURE;
         }
 
-        r = enumerate_sysv(lp, all_services);
+        r = enumerate_sysv(&lp, all_services);
         if (r < 0) {
                 log_error("Failed to generate units for all init scripts.");
                 return EXIT_FAILURE;
         }
 
-        r = set_dependencies_from_rcnd(lp, all_services);
+        r = set_dependencies_from_rcnd(&lp, all_services);
         if (r < 0) {
                 log_error("Failed to read runlevels from rcnd links.");
                 return EXIT_FAILURE;