summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-04-07 18:48:01 +0200
committerLennart Poettering <lennart@poettering.net>2016-04-12 13:43:32 +0200
commit4943d14306c3e456525fdb793e7f48efea5b9236 (patch)
tree01ebe6e1d8ff0563f279d45e78c8ddfc0723a164
parenta69b4fb0f80689b96f492a557368ed880365edee (diff)
systemctl: don't confuse sysv code with generated units
The SysV compat code checks whether there's a native unit file before looking for a SysV init script. Since the newest rework generated units will show up in the unit path, and hence the checks ended up assuming that there always was a native unit file for each init script: the generated one. With this change the generated unit file directory is suppressed from the search path when this check is done, to avoid the confusion.
-rw-r--r--src/core/manager.c4
-rw-r--r--src/shared/install.c24
-rw-r--r--src/shared/path-lookup.c14
-rw-r--r--src/shared/path-lookup.h6
-rw-r--r--src/systemctl/systemctl.c6
-rw-r--r--src/sysv-generator/sysv-generator.c2
-rw-r--r--src/test/test-path-lookup.c4
7 files changed, 34 insertions, 26 deletions
diff --git a/src/core/manager.c b/src/core/manager.c
index 91fe9c2d5b..5601770670 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -1097,7 +1097,7 @@ int manager_startup(Manager *m, FILE *serialization, FDSet *fds) {
assert(m);
- r = lookup_paths_init(&m->lookup_paths, m->unit_file_scope, NULL);
+ r = lookup_paths_init(&m->lookup_paths, m->unit_file_scope, 0, NULL);
if (r < 0)
return r;
@@ -2524,7 +2524,7 @@ int manager_reload(Manager *m) {
lookup_paths_flush_generator(&m->lookup_paths);
lookup_paths_free(&m->lookup_paths);
- q = lookup_paths_init(&m->lookup_paths, m->unit_file_scope, NULL);
+ q = lookup_paths_init(&m->lookup_paths, m->unit_file_scope, 0, NULL);
if (q < 0 && r >= 0)
r = q;
diff --git a/src/shared/install.c b/src/shared/install.c
index b5453adeee..7497a39219 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -1507,7 +1507,7 @@ int unit_file_mask(
assert(scope >= 0);
assert(scope < _UNIT_FILE_SCOPE_MAX);
- r = lookup_paths_init(&paths, scope, root_dir);
+ r = lookup_paths_init(&paths, scope, 0, root_dir);
if (r < 0)
return r;
@@ -1554,7 +1554,7 @@ int unit_file_unmask(
assert(scope >= 0);
assert(scope < _UNIT_FILE_SCOPE_MAX);
- r = lookup_paths_init(&paths, scope, root_dir);
+ r = lookup_paths_init(&paths, scope, 0, root_dir);
if (r < 0)
return r;
@@ -1636,7 +1636,7 @@ int unit_file_link(
assert(scope >= 0);
assert(scope < _UNIT_FILE_SCOPE_MAX);
- r = lookup_paths_init(&paths, scope, root_dir);
+ r = lookup_paths_init(&paths, scope, 0, root_dir);
if (r < 0)
return r;
@@ -1727,7 +1727,7 @@ int unit_file_add_dependency(
if (!unit_name_is_valid(target, UNIT_NAME_ANY))
return -EINVAL;
- r = lookup_paths_init(&paths, scope, root_dir);
+ r = lookup_paths_init(&paths, scope, 0, root_dir);
if (r < 0)
return r;
@@ -1791,7 +1791,7 @@ int unit_file_enable(
assert(scope >= 0);
assert(scope < _UNIT_FILE_SCOPE_MAX);
- r = lookup_paths_init(&paths, scope, root_dir);
+ r = lookup_paths_init(&paths, scope, 0, root_dir);
if (r < 0)
return r;
@@ -1834,7 +1834,7 @@ int unit_file_disable(
assert(scope >= 0);
assert(scope < _UNIT_FILE_SCOPE_MAX);
- r = lookup_paths_init(&paths, scope, root_dir);
+ r = lookup_paths_init(&paths, scope, 0, root_dir);
if (r < 0)
return r;
@@ -1907,7 +1907,7 @@ int unit_file_set_default(
if (streq(name, SPECIAL_DEFAULT_TARGET))
return -EINVAL;
- r = lookup_paths_init(&paths, scope, root_dir);
+ r = lookup_paths_init(&paths, scope, 0, root_dir);
if (r < 0)
return r;
@@ -1939,7 +1939,7 @@ int unit_file_get_default(
assert(scope < _UNIT_FILE_SCOPE_MAX);
assert(name);
- r = lookup_paths_init(&paths, scope, root_dir);
+ r = lookup_paths_init(&paths, scope, 0, root_dir);
if (r < 0)
return r;
@@ -2045,7 +2045,7 @@ int unit_file_get_state(
assert(scope < _UNIT_FILE_SCOPE_MAX);
assert(name);
- r = lookup_paths_init(&paths, scope, root_dir);
+ r = lookup_paths_init(&paths, scope, 0, root_dir);
if (r < 0)
return r;
@@ -2255,7 +2255,7 @@ int unit_file_preset(
assert(scope < _UNIT_FILE_SCOPE_MAX);
assert(mode < _UNIT_FILE_PRESET_MAX);
- r = lookup_paths_init(&paths, scope, root_dir);
+ r = lookup_paths_init(&paths, scope, 0, root_dir);
if (r < 0)
return r;
@@ -2292,7 +2292,7 @@ int unit_file_preset_all(
assert(scope < _UNIT_FILE_SCOPE_MAX);
assert(mode < _UNIT_FILE_PRESET_MAX);
- r = lookup_paths_init(&paths, scope, root_dir);
+ r = lookup_paths_init(&paths, scope, 0, root_dir);
if (r < 0)
return r;
@@ -2361,7 +2361,7 @@ int unit_file_get_list(
assert(scope < _UNIT_FILE_SCOPE_MAX);
assert(h);
- r = lookup_paths_init(&paths, scope, root_dir);
+ r = lookup_paths_init(&paths, scope, 0, root_dir);
if (r < 0)
return r;
diff --git a/src/shared/path-lookup.c b/src/shared/path-lookup.c
index 1c8e22eee7..ca69a0aef2 100644
--- a/src/shared/path-lookup.c
+++ b/src/shared/path-lookup.c
@@ -441,6 +441,7 @@ static int patch_root_prefix_strv(char **l, const char *root_dir) {
int lookup_paths_init(
LookupPaths *p,
UnitFileScope scope,
+ LookupPathsFlags flags,
const char *root_dir) {
_cleanup_free_ char
@@ -477,9 +478,11 @@ int lookup_paths_init(
if (r < 0 && r != -ENXIO)
return r;
- r = acquire_generator_dirs(scope, &generator, &generator_early, &generator_late);
- if (r < 0 && r != -EOPNOTSUPP && r != -ENXIO)
- return r;
+ if ((flags & LOOKUP_PATHS_EXCLUDE_GENERATED) == 0) {
+ r = acquire_generator_dirs(scope, &generator, &generator_early, &generator_late);
+ if (r < 0 && r != -EOPNOTSUPP && r != -ENXIO)
+ return r;
+ }
r = acquire_transient_dir(scope, &transient);
if (r < 0 && r != -EOPNOTSUPP && r != -ENXIO)
@@ -751,6 +754,9 @@ int lookup_paths_mkdir_generator(LookupPaths *p) {
assert(p);
+ if (!p->generator || !p->generator_early || !p->generator_late)
+ return -EINVAL;
+
r = mkdir_p_label(p->generator, 0755);
q = mkdir_p_label(p->generator_early, 0755);
@@ -771,10 +777,8 @@ void lookup_paths_trim_generator(LookupPaths *p) {
if (p->generator)
(void) rmdir(p->generator);
-
if (p->generator_early)
(void) rmdir(p->generator_early);
-
if (p->generator_late)
(void) rmdir(p->generator_late);
}
diff --git a/src/shared/path-lookup.h b/src/shared/path-lookup.h
index ad05c0c537..f9bb2fe237 100644
--- a/src/shared/path-lookup.h
+++ b/src/shared/path-lookup.h
@@ -26,6 +26,10 @@ typedef struct LookupPaths LookupPaths;
#include "install.h"
#include "macro.h"
+typedef enum LookupPathsFlags {
+ LOOKUP_PATHS_EXCLUDE_GENERATED = 1,
+} LookupPathsFlags;
+
struct LookupPaths {
/* Where we look for unit files. This includes the individual special paths below, but also any vendor
* supplied, static unit file paths. */
@@ -58,7 +62,7 @@ struct LookupPaths {
char *root_dir;
};
-int lookup_paths_init(LookupPaths *p, UnitFileScope scope, const char *root_dir);
+int lookup_paths_init(LookupPaths *p, UnitFileScope scope, LookupPathsFlags flags, const char *root_dir);
int lookup_paths_reduce(LookupPaths *p);
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 7c259ba06f..3344d25f77 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -4810,7 +4810,7 @@ static int cat(int argc, char *argv[], void *userdata) {
return -EINVAL;
}
- r = lookup_paths_init(&lp, arg_scope, arg_root);
+ r = lookup_paths_init(&lp, arg_scope, 0, arg_root);
if (r < 0)
return log_error_errno(r, "Failed to determine unit paths: %m");
@@ -5240,7 +5240,7 @@ static int enable_sysv_units(const char *verb, char **args) {
"is-enabled"))
return 0;
- r = lookup_paths_init(&paths, arg_scope, arg_root);
+ r = lookup_paths_init(&paths, arg_scope, LOOKUP_PATHS_EXCLUDE_GENERATED, arg_root);
if (r < 0)
return r;
@@ -6073,7 +6073,7 @@ static int find_paths_to_edit(sd_bus *bus, char **names, char ***paths) {
assert(names);
assert(paths);
- r = lookup_paths_init(&lp, arg_scope, arg_root);
+ r = lookup_paths_init(&lp, arg_scope, 0, arg_root);
if (r < 0)
return r;
diff --git a/src/sysv-generator/sysv-generator.c b/src/sysv-generator/sysv-generator.c
index fb7c47e1c8..e44304c16a 100644
--- a/src/sysv-generator/sysv-generator.c
+++ b/src/sysv-generator/sysv-generator.c
@@ -1004,7 +1004,7 @@ int main(int argc, char *argv[]) {
umask(0022);
- r = lookup_paths_init(&lp, UNIT_FILE_SYSTEM, NULL);
+ r = lookup_paths_init(&lp, UNIT_FILE_SYSTEM, LOOKUP_PATHS_EXCLUDE_GENERATED, NULL);
if (r < 0) {
log_error_errno(r, "Failed to find lookup paths: %m");
goto finish;
diff --git a/src/test/test-path-lookup.c b/src/test/test-path-lookup.c
index ba60482867..096326d176 100644
--- a/src/test/test-path-lookup.c
+++ b/src/test/test-path-lookup.c
@@ -36,13 +36,13 @@ static void test_paths(UnitFileScope scope) {
assert_se(mkdtemp(template));
assert_se(unsetenv("SYSTEMD_UNIT_PATH") == 0);
- assert_se(lookup_paths_init(&lp_without_env, scope, NULL) >= 0);
+ assert_se(lookup_paths_init(&lp_without_env, scope, 0, NULL) >= 0);
assert_se(!strv_isempty(lp_without_env.search_path));
assert_se(lookup_paths_reduce(&lp_without_env) >= 0);
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, scope, NULL) == 0);
+ assert_se(lookup_paths_init(&lp_with_env, scope, 0, 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(lookup_paths_reduce(&lp_with_env) >= 0);