diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-06-04 11:58:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-04 11:58:21 +0200 |
commit | 0be9b12be2eadfd9c296f12874dffb5d17c68484 (patch) | |
tree | 9d639f0acd3b9542788e7efd7788e356fc78986a /src/shared | |
parent | ec5b1452ac73e41274f9b3ca401f813fa079b9f0 (diff) | |
parent | 4910b35078ad24dcbc63f372b2fee087640201d0 (diff) | |
download | systemd-0be9b12be2eadfd9c296f12874dffb5d17c68484.tar.gz |
Merge pull request #9147 from keszybz/runtime-enablement
Runtime enablement
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/install.c | 175 |
1 files changed, 78 insertions, 97 deletions
diff --git a/src/shared/install.c b/src/shared/install.c index 46e07ebb98..e715338ac5 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -894,16 +894,13 @@ static int find_symlinks_in_scope( if (r > 0) { /* We found symlinks in this dir? Yay! Let's see where precisely it is enabled. */ - r = path_is_config(paths, *p, false); - if (r < 0) - return r; - if (r > 0) { + if (path_equal_ptr(*p, paths->persistent_config)) { /* This is the best outcome, let's return it immediately. */ *state = UNIT_FILE_ENABLED; return 1; } - /* look for globally enablement of user units */ + /* look for global enablement of user units */ if (scope == UNIT_FILE_USER && path_is_user_config_dir(*p)) { *state = UNIT_FILE_ENABLED; return 1; @@ -918,11 +915,7 @@ static int find_symlinks_in_scope( enabled_at_all = true; } else if (same_name_link) { - - r = path_is_config(paths, *p, false); - if (r < 0) - return r; - if (r > 0) + if (path_equal_ptr(*p, paths->persistent_config)) same_name_link_config = true; else { r = path_is_runtime(paths, *p, false); @@ -1923,7 +1916,6 @@ static int install_context_mark_for_removal( InstallContext *c, const LookupPaths *paths, Set **remove_symlinks_to, - const char *config_path, UnitFileChange **changes, size_t *n_changes) { @@ -1932,7 +1924,6 @@ static int install_context_mark_for_removal( assert(c); assert(paths); - assert(config_path); /* Marks all items for removal */ @@ -2042,7 +2033,7 @@ int unit_file_unmask( size_t n_todo = 0, n_allocated = 0; const char *config_path; char **i; - bool dry_run; + bool dry_run = !!(flags & UNIT_FILE_DRY_RUN); int r, q; assert(scope >= 0); @@ -2052,73 +2043,71 @@ int unit_file_unmask( if (r < 0) return r; - config_path = (flags & UNIT_FILE_RUNTIME) ? paths.runtime_config : paths.persistent_config; - if (!config_path) - return -ENXIO; - - dry_run = !!(flags & UNIT_FILE_DRY_RUN); - STRV_FOREACH(i, files) { - _cleanup_free_ char *path = NULL; - if (!unit_name_is_valid(*i, UNIT_NAME_ANY)) return -EINVAL; - path = path_make_absolute(*i, config_path); - if (!path) - return -ENOMEM; + FOREACH_STRING(config_path, paths.runtime_config, paths.persistent_config) { + _cleanup_free_ char *path = NULL; - r = null_or_empty_path(path); - if (r == -ENOENT) - continue; - if (r < 0) - return r; - if (r == 0) - continue; + path = path_make_absolute(*i, config_path); + if (!path) + return -ENOMEM; - if (!GREEDY_REALLOC0(todo, n_allocated, n_todo + 2)) - return -ENOMEM; + r = null_or_empty_path(path); + if (r == -ENOENT) + continue; + if (r < 0) + return r; + if (r == 0) + continue; - todo[n_todo] = strdup(*i); - if (!todo[n_todo]) - return -ENOMEM; + if (!GREEDY_REALLOC0(todo, n_allocated, n_todo + 2)) + return -ENOMEM; - n_todo++; + todo[n_todo] = strdup(*i); + if (!todo[n_todo]) + return -ENOMEM; + + n_todo++; + } } strv_uniq(todo); r = 0; - STRV_FOREACH(i, todo) { - _cleanup_free_ char *path = NULL; - const char *rp; + FOREACH_STRING(config_path, paths.runtime_config, paths.persistent_config) { + STRV_FOREACH(i, todo) { + _cleanup_free_ char *path = NULL; + const char *rp; - path = path_make_absolute(*i, config_path); - if (!path) - return -ENOMEM; + path = path_make_absolute(*i, config_path); + if (!path) + return -ENOMEM; - if (!dry_run && unlink(path) < 0) { - if (errno != ENOENT) { - if (r >= 0) - r = -errno; - unit_file_changes_add(changes, n_changes, -errno, path, NULL); + if (!dry_run && unlink(path) < 0) { + if (errno != ENOENT) { + if (r >= 0) + r = -errno; + unit_file_changes_add(changes, n_changes, -errno, path, NULL); + } + + continue; } - continue; - } + unit_file_changes_add(changes, n_changes, UNIT_FILE_UNLINK, path, NULL); - unit_file_changes_add(changes, n_changes, UNIT_FILE_UNLINK, path, NULL); + rp = skip_root(&paths, path); + q = mark_symlink_for_removal(&remove_symlinks_to, rp ?: path); + if (q < 0) + return q; + } - rp = skip_root(&paths, path); - q = mark_symlink_for_removal(&remove_symlinks_to, rp ?: path); - if (q < 0) - return q; + q = remove_marked_symlinks(remove_symlinks_to, config_path, &paths, dry_run, changes, n_changes); + if (r >= 0) + r = q; } - q = remove_marked_symlinks(remove_symlinks_to, config_path, &paths, dry_run, changes, n_changes); - if (r >= 0) - r = q; - return r; } @@ -2510,6 +2499,7 @@ int unit_file_disable( _cleanup_(lookup_paths_free) LookupPaths paths = {}; _cleanup_(install_context_done) InstallContext c = {}; _cleanup_set_free_free_ Set *remove_symlinks_to = NULL; + bool dry_run = !!(flags & UNIT_FILE_DRY_RUN); const char *config_path; char **i; int r; @@ -2521,10 +2511,6 @@ int unit_file_disable( if (r < 0) return r; - config_path = (flags & UNIT_FILE_RUNTIME) ? paths.runtime_config : paths.persistent_config; - if (!config_path) - return -ENXIO; - STRV_FOREACH(i, files) { if (!unit_name_is_valid(*i, UNIT_NAME_ANY)) return -EINVAL; @@ -2534,11 +2520,17 @@ int unit_file_disable( return r; } - r = install_context_mark_for_removal(scope, &c, &paths, &remove_symlinks_to, config_path, changes, n_changes); + r = install_context_mark_for_removal(scope, &c, &paths, &remove_symlinks_to, changes, n_changes); if (r < 0) return r; - return remove_marked_symlinks(remove_symlinks_to, config_path, &paths, !!(flags & UNIT_FILE_DRY_RUN), changes, n_changes); + FOREACH_STRING(config_path, paths.runtime_config, paths.persistent_config) { + r = remove_marked_symlinks(remove_symlinks_to, config_path, &paths, dry_run, changes, n_changes); + if (r < 0) + return r; + } + + return 0; } int unit_file_reenable( @@ -2922,45 +2914,45 @@ int unit_file_query_preset(UnitFileScope scope, const char *root_dir, const char static int execute_preset( UnitFileScope scope, + UnitFileFlags flags, InstallContext *plus, InstallContext *minus, const LookupPaths *paths, - const char *config_path, char **files, UnitFilePresetMode mode, - bool force, UnitFileChange **changes, size_t *n_changes) { - int r; + const char *config_path; + bool force = !!(flags & UNIT_FILE_FORCE); + bool runtime = !!(flags & UNIT_FILE_RUNTIME); + int r = 0, q; assert(plus); assert(minus); assert(paths); - assert(config_path); if (mode != UNIT_FILE_PRESET_ENABLE_ONLY) { _cleanup_set_free_free_ Set *remove_symlinks_to = NULL; - r = install_context_mark_for_removal(scope, minus, paths, &remove_symlinks_to, config_path, changes, n_changes); - if (r < 0) - return r; + q = install_context_mark_for_removal(scope, minus, paths, &remove_symlinks_to, changes, n_changes); + if (q < 0) + return q; - r = remove_marked_symlinks(remove_symlinks_to, config_path, paths, false, changes, n_changes); - } else - r = 0; + FOREACH_STRING(config_path, paths->runtime_config, paths->persistent_config) { + q = remove_marked_symlinks(remove_symlinks_to, config_path, paths, false, changes, n_changes); + if (r == 0) + r = q; + } + } if (mode != UNIT_FILE_PRESET_DISABLE_ONLY) { - int q; - /* Returns number of symlinks that where supposed to be installed. */ - q = install_context_apply(scope, plus, paths, config_path, force, SEARCH_LOAD, changes, n_changes); - if (r >= 0) { - if (q < 0) - r = q; - else - r += q; - } + q = install_context_apply(scope, plus, paths, + runtime ? paths->runtime_config : paths->persistent_config, + force, SEARCH_LOAD, changes, n_changes); + if (r == 0) + r = q; } return r; @@ -3024,7 +3016,6 @@ int unit_file_preset( _cleanup_(install_context_done) InstallContext plus = {}, minus = {}; _cleanup_(lookup_paths_free) LookupPaths paths = {}; _cleanup_(presets_freep) Presets presets = {}; - const char *config_path; char **i; int r; @@ -3036,10 +3027,6 @@ int unit_file_preset( if (r < 0) return r; - config_path = (flags & UNIT_FILE_RUNTIME) ? paths.runtime_config : paths.persistent_config; - if (!config_path) - return -ENXIO; - r = read_presets(scope, root_dir, &presets); if (r < 0) return r; @@ -3050,7 +3037,7 @@ int unit_file_preset( return r; } - return execute_preset(scope, &plus, &minus, &paths, config_path, files, mode, !!(flags & UNIT_FILE_FORCE), changes, n_changes); + return execute_preset(scope, flags, &plus, &minus, &paths, files, mode, changes, n_changes); } int unit_file_preset_all( @@ -3064,7 +3051,6 @@ int unit_file_preset_all( _cleanup_(install_context_done) InstallContext plus = {}, minus = {}; _cleanup_(lookup_paths_free) LookupPaths paths = {}; _cleanup_(presets_freep) Presets presets = {}; - const char *config_path = NULL; char **i; int r; @@ -3076,10 +3062,6 @@ int unit_file_preset_all( if (r < 0) return r; - config_path = (flags & UNIT_FILE_RUNTIME) ? paths.runtime_config : paths.persistent_config; - if (!config_path) - return -ENXIO; - r = read_presets(scope, root_dir, &presets); if (r < 0) return r; @@ -3097,7 +3079,6 @@ int unit_file_preset_all( } FOREACH_DIRENT(de, d, return -errno) { - if (!unit_name_is_valid(de->d_name, UNIT_NAME_ANY)) continue; @@ -3121,7 +3102,7 @@ int unit_file_preset_all( } } - return execute_preset(scope, &plus, &minus, &paths, config_path, NULL, mode, !!(flags & UNIT_FILE_FORCE), changes, n_changes); + return execute_preset(scope, flags, &plus, &minus, &paths, NULL, mode, changes, n_changes); } static void unit_file_list_free_one(UnitFileList *f) { |