]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: rework generator dir logic, move the dirs into LookupPaths structure
authorLennart Poettering <lennart@poettering.net>
Wed, 24 Feb 2016 14:31:33 +0000 (15:31 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 12 Apr 2016 11:43:29 +0000 (13:43 +0200)
A long time ago – when generators where first introduced – the directories for
them were randomly created via mkdtemp(). This was changed later so that they
use fixed name directories now. Let's make use of this, and add the genrator
dirs to the LookupPaths structure and into the unit file search path maintained
in it. This has the benefit that the generator dirs are now normal part of the
search path for all tools, and thus are shown in "systemctl list-unit-files"
too.

13 files changed:
src/core/dbus-manager.c
src/core/load-dropin.c
src/core/load-dropin.h
src/core/load-fragment.c
src/core/manager.c
src/core/manager.h
src/shared/install.c
src/shared/install.h
src/shared/path-lookup.c
src/shared/path-lookup.h
src/systemctl/systemctl.c
src/sysv-generator/sysv-generator.c
src/test/test-path-lookup.c

index 00372b92b4bb9cee0e66da95f429bc2ee8e50827..739bd14b9e7091299a46399ad0bb4a96873f3779 100644 (file)
@@ -1924,7 +1924,7 @@ const sd_bus_vtable bus_manager_vtable[] = {
         SD_BUS_PROPERTY("Environment", "as", NULL, offsetof(Manager, environment), 0),
         SD_BUS_PROPERTY("ConfirmSpawn", "b", bus_property_get_bool, offsetof(Manager, confirm_spawn), SD_BUS_VTABLE_PROPERTY_CONST),
         SD_BUS_PROPERTY("ShowStatus", "b", bus_property_get_bool, offsetof(Manager, show_status), SD_BUS_VTABLE_PROPERTY_CONST),
-        SD_BUS_PROPERTY("UnitPath", "as", NULL, offsetof(Manager, lookup_paths.unit_path), SD_BUS_VTABLE_PROPERTY_CONST),
+        SD_BUS_PROPERTY("UnitPath", "as", NULL, offsetof(Manager, lookup_paths.search_path), SD_BUS_VTABLE_PROPERTY_CONST),
         SD_BUS_PROPERTY("DefaultStandardOutput", "s", bus_property_get_exec_output, offsetof(Manager, default_std_output), SD_BUS_VTABLE_PROPERTY_CONST),
         SD_BUS_PROPERTY("DefaultStandardError", "s", bus_property_get_exec_output, offsetof(Manager, default_std_output), SD_BUS_VTABLE_PROPERTY_CONST),
         SD_BUS_WRITABLE_PROPERTY("RuntimeWatchdogUSec", "t", bus_property_get_usec, property_set_runtime_watchdog, offsetof(Manager, runtime_watchdog), 0),
index 22b71b6f5e5c04837fe7e8708e18f5c6a662c254..1c65055a3f483f0a5c65bc8fe1597a001c5bffea 100644 (file)
@@ -55,7 +55,7 @@ int unit_load_dropin(Unit *u) {
         SET_FOREACH(t, u->names, i) {
                 char **p;
 
-                STRV_FOREACH(p, u->manager->lookup_paths.unit_path) {
+                STRV_FOREACH(p, u->manager->lookup_paths.search_path) {
                         unit_file_process_dir(u->manager->unit_path_cache, *p, t, ".wants", UNIT_WANTS,
                                               add_dependency_consumer, u, NULL);
                         unit_file_process_dir(u->manager->unit_path_cache, *p, t, ".requires", UNIT_REQUIRES,
index d8a4aefbb3805a8118943f6f3e37bab46ac475ed..942d26724ed356cd80bae118d0b2ac6ba2b5dcc4 100644 (file)
@@ -25,7 +25,7 @@
 /* Read service data supplementary drop-in directories */
 
 static inline int unit_find_dropin_paths(Unit *u, char ***paths) {
-        return unit_file_find_dropin_paths(u->manager->lookup_paths.unit_path,
+        return unit_file_find_dropin_paths(u->manager->lookup_paths.search_path,
                                            u->manager->unit_path_cache,
                                            u->names,
                                            paths);
index f1a874cfdfbfe9e39180f54e2e46bb5063aa16b8..3a77ceb5518338c32b72087b9d25453cfa1e20ea 100644 (file)
@@ -3574,7 +3574,7 @@ static int load_from_path(Unit *u, const char *path) {
         } else  {
                 char **p;
 
-                STRV_FOREACH(p, u->manager->lookup_paths.unit_path) {
+                STRV_FOREACH(p, u->manager->lookup_paths.search_path) {
 
                         /* Instead of opening the path right away, we manually
                          * follow all symlinks and add their name to our unit
index e739795e7079b2be789a805b853e0e5a1bb3462e..79dc77d50e07cd37cec7217a0ef897c47e897c5a 100644 (file)
@@ -1053,7 +1053,7 @@ static void manager_build_unit_path_cache(Manager *m) {
         /* This simply builds a list of files we know exist, so that
          * we don't always have to go to disk */
 
-        STRV_FOREACH(i, m->lookup_paths.unit_path) {
+        STRV_FOREACH(i, m->lookup_paths.search_path) {
                 struct dirent *de;
 
                 d = opendir(*i);
@@ -1116,18 +1116,13 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds) {
 
         assert(m);
 
-        dual_timestamp_get(&m->generators_start_timestamp);
-        r = manager_run_generators(m);
-        dual_timestamp_get(&m->generators_finish_timestamp);
+        r = lookup_paths_init(&m->lookup_paths, m->running_as, true, NULL);
         if (r < 0)
                 return r;
 
-        r = lookup_paths_init(
-                        &m->lookup_paths, m->running_as, true,
-                        NULL,
-                        m->generator_unit_path,
-                        m->generator_unit_path_early,
-                        m->generator_unit_path_late);
+        dual_timestamp_get(&m->generators_start_timestamp);
+        r = manager_run_generators(m);
+        dual_timestamp_get(&m->generators_finish_timestamp);
         if (r < 0)
                 return r;
 
@@ -2542,17 +2537,12 @@ int manager_reload(Manager *m) {
         manager_undo_generators(m);
         lookup_paths_free(&m->lookup_paths);
 
-        /* Find new unit paths */
-        q = manager_run_generators(m);
+        q = lookup_paths_init(&m->lookup_paths, m->running_as, true, NULL);
         if (q < 0 && r >= 0)
                 r = q;
 
-        q = lookup_paths_init(
-                        &m->lookup_paths, m->running_as, true,
-                        NULL,
-                        m->generator_unit_path,
-                        m->generator_unit_path_early,
-                        m->generator_unit_path_late);
+        /* Find new unit paths */
+        q = manager_run_generators(m);
         if (q < 0 && r >= 0)
                 r = q;
 
@@ -2732,77 +2722,6 @@ void manager_check_finished(Manager *m) {
         manager_invalidate_startup_units(m);
 }
 
-static int create_generator_dir(Manager *m, char **generator, const char *name) {
-        char *p;
-        int r;
-
-        assert(m);
-        assert(generator);
-        assert(name);
-
-        if (*generator)
-                return 0;
-
-        if (m->running_as == MANAGER_SYSTEM && getpid() == 1) {
-                /* systemd --system, not running --test */
-
-                p = strappend("/run/systemd/", name);
-                if (!p)
-                        return log_oom();
-
-                r = mkdir_p_label(p, 0755);
-                if (r < 0) {
-                        log_error_errno(r, "Failed to create generator directory %s: %m", p);
-                        free(p);
-                        return r;
-                }
-        } else if (m->running_as == MANAGER_USER) {
-                const char *s = NULL;
-
-                s = getenv("XDG_RUNTIME_DIR");
-                if (!s)
-                        return -EINVAL;
-                p = strjoin(s, "/systemd/", name, NULL);
-                if (!p)
-                        return log_oom();
-
-                r = mkdir_p_label(p, 0755);
-                if (r < 0) {
-                        log_error_errno(r, "Failed to create generator directory %s: %m", p);
-                        free(p);
-                        return r;
-                }
-        } else {
-                /* systemd --system --test */
-
-                p = strjoin("/tmp/systemd-", name, ".XXXXXX", NULL);
-                if (!p)
-                        return log_oom();
-
-                if (!mkdtemp(p)) {
-                        log_error_errno(errno, "Failed to create generator directory %s: %m", p);
-                        free(p);
-                        return -errno;
-                }
-        }
-
-        *generator = p;
-        return 0;
-}
-
-static void trim_generator_dir(Manager *m, char **generator) {
-        assert(m);
-        assert(generator);
-
-        if (!*generator)
-                return;
-
-        if (rmdir(*generator) >= 0)
-                *generator = mfree(*generator);
-
-        return;
-}
-
 static int manager_run_generators(Manager *m) {
         _cleanup_strv_free_ char **paths = NULL;
         const char *argv[5];
@@ -2821,62 +2740,53 @@ static int manager_run_generators(Manager *m) {
         /* Optimize by skipping the whole process by not creating output directories
          * if no generators are found. */
         STRV_FOREACH(path, paths) {
-                r = access(*path, F_OK);
-                if (r == 0)
+                if (access(*path, F_OK) >= 0)
                         goto found;
                 if (errno != ENOENT)
                         log_warning_errno(errno, "Failed to open generator directory %s: %m", *path);
         }
+
         return 0;
 
  found:
-        r = create_generator_dir(m, &m->generator_unit_path, "generator");
+        r = mkdir_p_label(m->lookup_paths.generator, 0755);
         if (r < 0)
                 goto finish;
 
-        r = create_generator_dir(m, &m->generator_unit_path_early, "generator.early");
+        r = mkdir_p_label(m->lookup_paths.generator_early, 0755);
         if (r < 0)
                 goto finish;
 
-        r = create_generator_dir(m, &m->generator_unit_path_late, "generator.late");
+        r = mkdir_p_label(m->lookup_paths.generator_late, 0755);
         if (r < 0)
                 goto finish;
 
         argv[0] = NULL; /* Leave this empty, execute_directory() will fill something in */
-        argv[1] = m->generator_unit_path;
-        argv[2] = m->generator_unit_path_early;
-        argv[3] = m->generator_unit_path_late;
+        argv[1] = m->lookup_paths.generator;
+        argv[2] = m->lookup_paths.generator_early;
+        argv[3] = m->lookup_paths.generator_late;
         argv[4] = NULL;
 
         RUN_WITH_UMASK(0022)
                 execute_directories((const char* const*) paths, DEFAULT_TIMEOUT_USEC, (char**) argv);
 
 finish:
-        trim_generator_dir(m, &m->generator_unit_path);
-        trim_generator_dir(m, &m->generator_unit_path_early);
-        trim_generator_dir(m, &m->generator_unit_path_late);
+        /* Trim empty dirs */
+        (void) rmdir(m->lookup_paths.generator);
+        (void) rmdir(m->lookup_paths.generator_early);
+        (void) rmdir(m->lookup_paths.generator_late);
         return r;
 }
 
-static void remove_generator_dir(Manager *m, char **generator) {
-        assert(m);
-        assert(generator);
-
-        if (!*generator)
-                return;
-
-        strv_remove(m->lookup_paths.unit_path, *generator);
-        (void) rm_rf(*generator, REMOVE_ROOT);
-
-        *generator = mfree(*generator);
-}
-
 static void manager_undo_generators(Manager *m) {
         assert(m);
 
-        remove_generator_dir(m, &m->generator_unit_path);
-        remove_generator_dir(m, &m->generator_unit_path_early);
-        remove_generator_dir(m, &m->generator_unit_path_late);
+        if (m->lookup_paths.generator)
+                (void) rm_rf(m->lookup_paths.generator, REMOVE_ROOT);
+        if (m->lookup_paths.generator_early)
+                (void) rm_rf(m->lookup_paths.generator_early, REMOVE_ROOT);
+        if (m->lookup_paths.generator_late)
+                (void) rm_rf(m->lookup_paths.generator_late, REMOVE_ROOT);
 }
 
 int manager_environment_add(Manager *m, char **minus, char **plus) {
index 9803f731295b9759eccebb30e0d2a987492160b9..5471bd7a0d54afbc633d2e20c6b678312c0eba30 100644 (file)
@@ -162,10 +162,6 @@ struct Manager {
         dual_timestamp units_load_start_timestamp;
         dual_timestamp units_load_finish_timestamp;
 
-        char *generator_unit_path;
-        char *generator_unit_path_early;
-        char *generator_unit_path_late;
-
         struct udev* udev;
 
         /* Data specific to the device subsystem */
index 0f08137f19e81ced7166eaa8e73b57e34954d941..e232d76dd75da0f9f66ba014672008f935f7fb74 100644 (file)
@@ -1060,7 +1060,7 @@ static int unit_file_search(
 
         assert(info->name);
 
-        STRV_FOREACH(p, paths->unit_path) {
+        STRV_FOREACH(p, paths->search_path) {
                 _cleanup_free_ char *path = NULL;
 
                 path = strjoin(*p, "/", info->name, NULL);
@@ -1090,7 +1090,7 @@ static int unit_file_search(
                 if (r < 0)
                         return r;
 
-                STRV_FOREACH(p, paths->unit_path) {
+                STRV_FOREACH(p, paths->search_path) {
                         _cleanup_free_ char *path = NULL;
 
                         path = strjoin(*p, "/", template, NULL);
@@ -1348,7 +1348,7 @@ static int install_info_symlink_link(
         assert(config_path);
         assert(i->path);
 
-        r = in_search_path(i->path, paths->unit_path);
+        r = in_search_path(i->path, paths->search_path);
         if (r != 0)
                 return r;
 
@@ -1672,7 +1672,7 @@ int unit_file_link(
                 if (!S_ISREG(st.st_mode))
                         return -ENOTTY;
 
-                q = in_search_path(*i, paths.unit_path);
+                q = in_search_path(*i, paths.search_path);
                 if (q < 0)
                         return q;
                 if (q > 0)
@@ -2313,7 +2313,7 @@ int unit_file_preset_all(
         if (r < 0)
                 return r;
 
-        STRV_FOREACH(i, paths.unit_path) {
+        STRV_FOREACH(i, paths.search_path) {
                 _cleanup_closedir_ DIR *d = NULL;
                 _cleanup_free_ char *units_dir;
                 struct dirent *de;
@@ -2389,7 +2389,7 @@ int unit_file_get_list(
         if (r < 0)
                 return r;
 
-        STRV_FOREACH(i, paths.unit_path) {
+        STRV_FOREACH(i, paths.search_path) {
                 _cleanup_closedir_ DIR *d = NULL;
                 _cleanup_free_ char *units_dir;
                 struct dirent *de;
index c1a43e23e70d147a45f5a1b20fc032a5dc8f62c8..82b6d425eb1513807ef33716939076bb62e29e2d 100644 (file)
@@ -135,7 +135,7 @@ 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, const char *target, UnitDependency dep, bool force, UnitFileChange **changes, unsigned *n_changes);
 
-int unit_file_lookup_state(UnitFileScope scope, const char *root_dir,const LookupPaths *paths, const char *name, UnitFileState *ret);
+int unit_file_lookup_state(UnitFileScope scope, const char *root_dir, const LookupPaths *paths, const char *name, UnitFileState *ret);
 int unit_file_get_state(UnitFileScope scope, const char *root_dir, const char *filename, UnitFileState *ret);
 
 int unit_file_get_list(UnitFileScope scope, const char *root_dir, Hashmap *h);
index ac22a27ccbd99cc97332249edb169f2ce9214109..ec3f5b53f4151332e2d39423be647834587188cd 100644 (file)
@@ -235,43 +235,119 @@ char **generator_paths(ManagerRunningAs running_as) {
                                 NULL);
 }
 
+static int acquire_generator_dirs(
+                ManagerRunningAs running_as,
+                char **generator,
+                char **generator_early,
+                char **generator_late) {
+
+        _cleanup_free_ char *x = NULL, *y = NULL, *z = NULL;
+        const char *prefix;
+
+        assert(generator);
+        assert(generator_early);
+        assert(generator_late);
+
+        if (running_as == MANAGER_SYSTEM)
+                prefix = "/run/systemd/";
+        else {
+                const char *e;
+
+                assert(running_as == MANAGER_USER);
+
+                e = getenv("XDG_RUNTIME_DIR");
+                if (!e)
+                        return -EINVAL;
+
+                prefix = strjoina(e, "/systemd/", NULL);
+        }
+
+        x = strappend(prefix, "generator");
+        if (!x)
+                return -ENOMEM;
+
+        y = strappend(prefix, "generator.early");
+        if (!y)
+                return -ENOMEM;
+
+        z = strappend(prefix, "generator.late");
+        if (!z)
+                return -ENOMEM;
+
+        *generator = x;
+        *generator_early = y;
+        *generator_late = z;
+
+        x = y = z = NULL;
+        return 0;
+}
+
+static int patch_root_prefix(char **p, const char *root_dir) {
+        char *c;
+
+        assert(p);
+
+        if (!*p)
+                return 0;
+
+        if (isempty(root_dir) || path_equal(root_dir, "/"))
+                return 0;
+
+        c = prefix_root(root_dir, *p);
+        if (!c)
+                return -ENOMEM;
+
+        free(*p);
+        *p = c;
+
+        return 0;
+}
+
 int lookup_paths_init(
                 LookupPaths *p,
                 ManagerRunningAs running_as,
                 bool personal,
-                const char *root_dir,
-                const char *generator,
-                const char *generator_early,
-                const char *generator_late) {
+                const char *root_dir) {
 
-        const char *e;
+        _cleanup_free_ char *generator = NULL, *generator_early = NULL, *generator_late = NULL;
         bool append = false; /* Add items from SYSTEMD_UNIT_PATH before normal directories */
+        char **l = NULL;
+        const char *e;
         int r;
 
         assert(p);
+        assert(running_as >= 0);
+        assert(running_as < _MANAGER_RUNNING_AS_MAX);
+
+        r = acquire_generator_dirs(running_as, &generator, &generator_early, &generator_late);
+        if (r < 0)
+                return r;
 
         /* First priority is whatever has been passed to us via env
          * vars */
         e = getenv("SYSTEMD_UNIT_PATH");
         if (e) {
-                if (endswith(e, ":")) {
-                        e = strndupa(e, strlen(e) - 1);
+                const char *k;
+
+                k = endswith(e, ":");
+                if (k) {
+                        e = strndupa(e, k - e);
                         append = true;
                 }
 
                 /* FIXME: empty components in other places should be
                  * rejected. */
 
-                r = path_split_and_make_absolute(e, &p->unit_path);
+                r = path_split_and_make_absolute(e, &l);
                 if (r < 0)
                         return r;
         } else
-                p->unit_path = NULL;
+                l = NULL;
 
-        if (!p->unit_path || append) {
+        if (!l || append) {
                 /* Let's figure something out. */
 
-                _cleanup_strv_free_ char **unit_path;
+                _cleanup_strv_free_ char **add = NULL;
 
                 /* For the user units we include share/ in the search
                  * path in order to comply with the XDG basedir spec.
@@ -281,85 +357,114 @@ int lookup_paths_init(
 
                 if (running_as == MANAGER_USER) {
                         if (personal)
-                                unit_path = user_dirs(generator, generator_early, generator_late);
+                                add = user_dirs(generator, generator_early, generator_late);
                         else
-                                unit_path = strv_new(
+                                add = strv_new(
                                         /* If you modify this you also want to modify
                                          * systemduserunitpath= in systemd.pc.in, and
                                          * the arrays in user_dirs() above! */
-                                        STRV_IFNOTNULL(generator_early),
+                                        generator_early,
                                         USER_CONFIG_UNIT_PATH,
                                         "/etc/systemd/user",
                                         "/run/systemd/user",
-                                        STRV_IFNOTNULL(generator),
+                                        generator,
                                         "/usr/local/lib/systemd/user",
                                         "/usr/local/share/systemd/user",
                                         USER_DATA_UNIT_PATH,
                                         "/usr/lib/systemd/user",
                                         "/usr/share/systemd/user",
-                                        STRV_IFNOTNULL(generator_late),
+                                        generator_late,
                                         NULL);
                 } else
-                        unit_path = strv_new(
+                        add = strv_new(
                                 /* If you modify this you also want to modify
                                  * systemdsystemunitpath= in systemd.pc.in! */
-                                STRV_IFNOTNULL(generator_early),
+                                generator_early,
                                 SYSTEM_CONFIG_UNIT_PATH,
                                 "/etc/systemd/system",
                                 "/run/systemd/system",
-                                STRV_IFNOTNULL(generator),
+                                generator,
                                 "/usr/local/lib/systemd/system",
                                 SYSTEM_DATA_UNIT_PATH,
                                 "/usr/lib/systemd/system",
 #ifdef HAVE_SPLIT_USR
                                 "/lib/systemd/system",
 #endif
-                                STRV_IFNOTNULL(generator_late),
+                                generator_late,
                                 NULL);
 
-                if (!unit_path)
+                if (!add)
                         return -ENOMEM;
 
-                r = strv_extend_strv(&p->unit_path, unit_path, false);
-                if (r < 0)
-                        return r;
+                if (l) {
+                        r = strv_extend_strv(&l, add, false);
+                        if (r < 0)
+                                return r;
+                } else {
+                        l = add;
+                        add = NULL;
+                }
         }
 
-        if (!path_strv_resolve_uniq(p->unit_path, root_dir))
+        r = patch_root_prefix(&generator, root_dir);
+        if (r < 0)
+                return r;
+        r = patch_root_prefix(&generator_early, root_dir);
+        if (r < 0)
+                return r;
+        r = patch_root_prefix(&generator_late, root_dir);
+        if (r < 0)
+                return r;
+
+        if (!path_strv_resolve_uniq(l, root_dir))
                 return -ENOMEM;
 
-        if (!strv_isempty(p->unit_path)) {
-                _cleanup_free_ char *t = strv_join(p->unit_path, "\n\t");
+        if (strv_isempty(l)) {
+                log_debug("Ignoring unit files.");
+                l = strv_free(l);
+        } else {
+                _cleanup_free_ char *t;
+
+                t = strv_join(l, "\n\t");
                 if (!t)
                         return -ENOMEM;
+
                 log_debug("Looking for unit files in (higher priority first):\n\t%s", t);
-        } else {
-                log_debug("Ignoring unit files.");
-                p->unit_path = strv_free(p->unit_path);
         }
 
+        p->search_path = l;
+        l = NULL;
+
+        p->generator = generator;
+        p->generator_early = generator_early;
+        p->generator_late = generator_late;
+        generator = generator_early = generator_late = NULL;
 
         return 0;
 }
 
 void lookup_paths_free(LookupPaths *p) {
-        assert(p);
+        if (!p)
+                return;
 
-        p->unit_path = strv_free(p->unit_path);
+        p->search_path = strv_free(p->search_path);
+        p->generator = mfree(p->generator);
+        p->generator_early = mfree(p->generator_early);
+        p->generator_late = mfree(p->generator_late);
 }
 
-int lookup_paths_init_from_scope(LookupPaths *paths,
-                                 UnitFileScope scope,
-                                 const char *root_dir) {
-        assert(paths);
+int lookup_paths_init_from_scope(
+                LookupPaths *p,
+                UnitFileScope scope,
+                const char *root_dir) {
+
+        assert(p);
         assert(scope >= 0);
         assert(scope < _UNIT_FILE_SCOPE_MAX);
 
-        zero(*paths);
-
-        return lookup_paths_init(paths,
-                                 scope == UNIT_FILE_SYSTEM ? MANAGER_SYSTEM : MANAGER_USER,
-                                 scope == UNIT_FILE_USER,
-                                 root_dir,
-                                 NULL, NULL, NULL);
+        return lookup_paths_init(
+                        p,
+                        scope == UNIT_FILE_SYSTEM ? MANAGER_SYSTEM : MANAGER_USER,
+                        scope == UNIT_FILE_USER,
+                        root_dir);
 }
index c53d29307201effc3c268b0d04355ea4e16a3690..1e3bce21a4cdc5ba855d8d5ece26265feb48bce6 100644 (file)
 ***/
 
 #include <stdbool.h>
+
+typedef struct LookupPaths LookupPaths;
+typedef enum ManagerRunningAs ManagerRunningAs;
+
+#include "install.h"
 #include "macro.h"
 
-typedef struct LookupPaths {
-        char **unit_path;
-} LookupPaths;
+struct LookupPaths {
+        char **search_path;
+        char *generator;
+        char *generator_early;
+        char *generator_late;
+};
 
-typedef enum ManagerRunningAs {
+enum ManagerRunningAs {
         MANAGER_SYSTEM,
         MANAGER_USER,
         _MANAGER_RUNNING_AS_MAX,
         _MANAGER_RUNNING_AS_INVALID = -1
-} ManagerRunningAs;
+};
 
 int user_config_home(char **config_home);
 int user_runtime_dir(char **runtime_dir);
 
 char **generator_paths(ManagerRunningAs running_as);
 
-int lookup_paths_init(LookupPaths *p,
-                      ManagerRunningAs running_as,
-                      bool personal,
-                      const char *root_dir,
-                      const char *generator,
-                      const char *generator_early,
-                      const char *generator_late);
-
-#include "install.h"
-
-int lookup_paths_init_from_scope(LookupPaths *paths,
-                                 UnitFileScope scope,
-                                 const char *root_dir);
+int lookup_paths_init(LookupPaths *p, ManagerRunningAs running_as, bool personal, const char *root_dir);
+int lookup_paths_init_from_scope(LookupPaths *p, UnitFileScope scope, const char *root_dir);
 
 void lookup_paths_free(LookupPaths *p);
 #define _cleanup_lookup_paths_free_ _cleanup_(lookup_paths_free)
index 62cff3a677cf7491ed7aa5bc33833829332a3943..4d0b4754ae74eab62098f6184a7b83a569b02523 100644 (file)
@@ -2295,7 +2295,7 @@ static int unit_file_find_path(LookupPaths *lp, const char *unit_name, char **un
         assert(unit_name);
         assert(unit_path);
 
-        STRV_FOREACH(p, lp->unit_path) {
+        STRV_FOREACH(p, lp->search_path) {
                 _cleanup_free_ char *path;
 
                 path = path_join(arg_root, *p, unit_name);
@@ -2395,7 +2395,7 @@ static int unit_find_paths(
                 }
 
                 if (dropin_paths) {
-                        r = unit_file_find_dropin_paths(lp->unit_path, NULL, names, &dropins);
+                        r = unit_file_find_dropin_paths(lp->search_path, NULL, names, &dropins);
                         if (r < 0)
                                 return r;
                 }
@@ -5271,7 +5271,7 @@ static int enable_sysv_units(const char *verb, char **args) {
         /* Processes all SysV units, and reshuffles the array so that
          * afterwards only the native units remain */
 
-        r = lookup_paths_init(&paths, MANAGER_SYSTEM, false, arg_root, NULL, NULL, NULL);
+        r = lookup_paths_init(&paths, MANAGER_SYSTEM, false, arg_root);
         if (r < 0)
                 return r;
 
@@ -5295,7 +5295,7 @@ static int enable_sysv_units(const char *verb, char **args) {
                 if (path_is_absolute(name))
                         continue;
 
-                STRV_FOREACH(k, paths.unit_path) {
+                STRV_FOREACH(k, paths.search_path) {
                         _cleanup_free_ char *path = NULL;
 
                         path = path_join(arg_root, *k, name);
index ca28c724ddccf642b8429317b29a20f142ef1def..b82c877dc782227f09138a845f81a050f5adc300 100644 (file)
@@ -1004,7 +1004,7 @@ int main(int argc, char *argv[]) {
 
         umask(0022);
 
-        r = lookup_paths_init(&lp, MANAGER_SYSTEM, true, NULL, NULL, NULL, NULL);
+        r = lookup_paths_init(&lp, MANAGER_SYSTEM, true, NULL);
         if (r < 0) {
                 log_error_errno(r, "Failed to find lookup paths: %m");
                 goto finish;
index 268da002a949281e70ca2eea8a092af1f9357930..ebb11dcb6d94d7f01d8bd143e0c7b00e1a3b04bb 100644 (file)
@@ -31,25 +31,20 @@ static void test_paths(ManagerRunningAs running_as, bool personal) {
 
         _cleanup_lookup_paths_free_ LookupPaths lp_without_env = {};
         _cleanup_lookup_paths_free_ LookupPaths lp_with_env = {};
-        char *exists, *not, *systemd_unit_path;
+        char *systemd_unit_path;
 
         assert_se(mkdtemp(template));
-        exists = strjoina(template, "/exists");
-        assert_se(mkdir(exists, 0755) == 0);
-        not = strjoina(template, "/not");
 
         assert_se(unsetenv("SYSTEMD_UNIT_PATH") == 0);
-        assert_se(lookup_paths_init(&lp_without_env, running_as, personal, NULL, exists, not, not) == 0);
+        assert_se(lookup_paths_init(&lp_without_env, running_as, personal, NULL) == 0);
 
-        assert_se(!strv_isempty(lp_without_env.unit_path));
-        assert_se(strv_contains(lp_without_env.unit_path, exists));
-        assert_se(strv_contains(lp_without_env.unit_path, not));
+        assert_se(!strv_isempty(lp_without_env.search_path));
 
         systemd_unit_path = strjoina(template, "/systemd-unit-path");
         assert_se(setenv("SYSTEMD_UNIT_PATH", systemd_unit_path, 1) == 0);
-        assert_se(lookup_paths_init(&lp_with_env, running_as, personal, NULL, exists, not, not) == 0);
-        assert_se(strv_length(lp_with_env.unit_path) == 1);
-        assert_se(streq(lp_with_env.unit_path[0], systemd_unit_path));
+        assert_se(lookup_paths_init(&lp_with_env, running_as, personal, NULL) == 0);
+        assert_se(strv_length(lp_with_env.search_path) == 1);
+        assert_se(streq(lp_with_env.search_path[0], systemd_unit_path));
 
         assert_se(rm_rf(template, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0);
 }