summaryrefslogtreecommitdiffstats
path: root/src/shared/install.c
diff options
context:
space:
mode:
authorMike Yuan <me@yhndnzj.com>2024-05-01 11:21:33 +0200
committerLuca Boccassi <bluca@debian.org>2024-06-12 00:17:21 +0200
commit521a7c9bb9cbfbe719b6bdfe3490e93f7548a13a (patch)
treec07d54010d5f099a0191a89203c17d68c78b875e /src/shared/install.c
parentshared/install: replace streq + basename with path_equal_filename (diff)
downloadsystemd-521a7c9bb9cbfbe719b6bdfe3490e93f7548a13a.tar.xz
systemd-521a7c9bb9cbfbe719b6bdfe3490e93f7548a13a.zip
shared/install: use FOREACH_ARRAY at one more place
Diffstat (limited to '')
-rw-r--r--src/shared/install.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/shared/install.c b/src/shared/install.c
index 06613235f9..a184cbef23 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -3398,6 +3398,8 @@ static int pattern_match_multiple_instances(
_cleanup_free_ char *templated_name = NULL;
int r;
+ assert(unit_name);
+
/* If no ret is needed or the rule itself does not have instances
* initialized, we return not matching */
if (!ret || !rule.instances)
@@ -3444,20 +3446,25 @@ static int pattern_match_multiple_instances(
static int query_presets(const char *name, const UnitFilePresets *presets, char ***instance_name_list) {
PresetAction action = PRESET_UNKNOWN;
+ assert(name);
+ assert(presets);
+
if (!unit_name_is_valid(name, UNIT_NAME_ANY))
return -EINVAL;
- for (size_t i = 0; i < presets->n_rules; i++)
- if (pattern_match_multiple_instances(presets->rules[i], name, instance_name_list) > 0 ||
- fnmatch(presets->rules[i].pattern, name, FNM_NOESCAPE) == 0) {
- action = presets->rules[i].action;
+ FOREACH_ARRAY(i, presets->rules, presets->n_rules)
+ if (pattern_match_multiple_instances(*i, name, instance_name_list) > 0 ||
+ fnmatch(i->pattern, name, FNM_NOESCAPE) == 0) {
+ action = i->action;
break;
}
switch (action) {
+
case PRESET_UNKNOWN:
log_debug("Preset files don't specify rule for %s. Enabling.", name);
return PRESET_ENABLE;
+
case PRESET_ENABLE:
if (instance_name_list && *instance_name_list)
STRV_FOREACH(s, *instance_name_list)
@@ -3465,12 +3472,15 @@ static int query_presets(const char *name, const UnitFilePresets *presets, char
else
log_debug("Preset files say enable %s.", name);
return PRESET_ENABLE;
+
case PRESET_DISABLE:
log_debug("Preset files say disable %s.", name);
return PRESET_DISABLE;
+
case PRESET_IGNORE:
log_debug("Preset files say ignore %s.", name);
return PRESET_IGNORE;
+
default:
assert_not_reached();
}