]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shared/install: use FOREACH_ARRAY at one more place
authorMike Yuan <me@yhndnzj.com>
Wed, 1 May 2024 09:21:33 +0000 (17:21 +0800)
committerLuca Boccassi <bluca@debian.org>
Tue, 11 Jun 2024 22:17:21 +0000 (23:17 +0100)
src/shared/install.c

index 06613235f96a2207a946177366c6b172ff1cbd25..a184cbef2355cca7d46d87b6f75e9079ad74eed6 100644 (file)
@@ -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();
         }