diff options
author | Daan De Meyer <daan.j.demeyer@gmail.com> | 2023-04-13 19:03:43 +0200 |
---|---|---|
committer | Luca Boccassi <luca.boccassi@gmail.com> | 2023-04-14 20:27:59 +0100 |
commit | e77e07f60186b96a9b5df398e92a18a72918e0f2 (patch) | |
tree | a027c2307414487484f58dea1a1c2752becda4ed /src/shared/install.c | |
parent | 6e4ec79a3cc5a24d9a5ac53c3737c4d398ac383d (diff) | |
download | systemd-e77e07f60186b96a9b5df398e92a18a72918e0f2.tar.gz |
preset: Add ignore directive
The ignore directive specifies to not do anything with the given
unit and leave existing configuration intact. This allows distributions
to gradually adopt preset files by shipping a ignore * preset file.
Diffstat (limited to 'src/shared/install.c')
-rw-r--r-- | src/shared/install.c | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/src/shared/install.c b/src/shared/install.c index eddc41964a..152e517ebc 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -52,18 +52,22 @@ typedef struct { OrderedHashmap *have_processed; } InstallContext; -typedef enum { - PRESET_UNKNOWN, - PRESET_ENABLE, - PRESET_DISABLE, -} PresetAction; - struct UnitFilePresetRule { char *pattern; PresetAction action; char **instances; }; +/* NB! strings use past tense. */ +static const char *const preset_action_past_tense_table[_PRESET_ACTION_MAX] = { + [PRESET_UNKNOWN] = "unknown", + [PRESET_ENABLE] = "enabled", + [PRESET_DISABLE] = "disabled", + [PRESET_IGNORE] = "ignored", +}; + +DEFINE_STRING_TABLE_LOOKUP_TO_STRING(preset_action_past_tense, PresetAction); + static bool install_info_has_rules(const InstallInfo *i) { assert(i); @@ -3297,6 +3301,20 @@ static int read_presets(RuntimeScope scope, const char *root_dir, UnitFilePreset }; } + parameter = first_word(l, "ignore"); + if (parameter) { + char *pattern; + + pattern = strdup(parameter); + if (!pattern) + return -ENOMEM; + + rule = (UnitFilePresetRule) { + .pattern = pattern, + .action = PRESET_IGNORE, + }; + } + if (rule.action) { if (!GREEDY_REALLOC(ps.rules, ps.n_rules + 1)) return -ENOMEM; @@ -3382,23 +3400,26 @@ static int query_presets(const char *name, const UnitFilePresets *presets, char switch (action) { case PRESET_UNKNOWN: log_debug("Preset files don't specify rule for %s. Enabling.", name); - return 1; + return PRESET_ENABLE; case PRESET_ENABLE: if (instance_name_list && *instance_name_list) STRV_FOREACH(s, *instance_name_list) log_debug("Preset files say enable %s.", *s); else log_debug("Preset files say enable %s.", name); - return 1; + return PRESET_ENABLE; case PRESET_DISABLE: log_debug("Preset files say disable %s.", name); - return 0; + return PRESET_DISABLE; + case PRESET_IGNORE: + log_debug("Preset files say ignore %s.", name); + return PRESET_IGNORE; default: assert_not_reached(); } } -int unit_file_query_preset(RuntimeScope scope, const char *root_dir, const char *name, UnitFilePresets *cached) { +PresetAction unit_file_query_preset(RuntimeScope scope, const char *root_dir, const char *name, UnitFilePresets *cached) { _cleanup_(unit_file_presets_done) UnitFilePresets tmp = {}; int r; @@ -3492,7 +3513,7 @@ static int preset_prepare_one( if (r < 0) return r; - if (r > 0) { + if (r == PRESET_ENABLE) { if (instance_name_list) STRV_FOREACH(s, instance_name_list) { r = install_info_discover_and_check(plus, lp, *s, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS, @@ -3507,7 +3528,7 @@ static int preset_prepare_one( return r; } - } else + } else if (r == PRESET_DISABLE) r = install_info_discover(minus, lp, name, SEARCH_FOLLOW_CONFIG_SYMLINKS, &info, changes, n_changes); |