]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
various: use FOREACH_ARRAY more
authorMike Yuan <me@yhndnzj.com>
Mon, 25 Dec 2023 09:57:01 +0000 (17:57 +0800)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 25 Dec 2023 11:17:48 +0000 (20:17 +0900)
Prompted by #30622

src/core/dbus-job.c
src/shared/compare-operator.c
src/shared/mount-setup.c

index 56ad88570f11cda3e2a5bfb251ecbb7fa472ce65..d5b50e8518360ddf4c570a127e0f1100fb40cc69 100644 (file)
@@ -87,22 +87,23 @@ int bus_job_method_get_waiting_jobs(sd_bus_message *message, void *userdata, sd_
         if (r < 0)
                 return r;
 
-        for (int i = 0; i < n; i++) {
+        FOREACH_ARRAY(i, list, n) {
                 _cleanup_free_ char *unit_path = NULL, *job_path = NULL;
+                Job *job = *i;
 
-                job_path = job_dbus_path(list[i]);
+                job_path = job_dbus_path(job);
                 if (!job_path)
                         return -ENOMEM;
 
-                unit_path = unit_dbus_path(list[i]->unit);
+                unit_path = unit_dbus_path(job->unit);
                 if (!unit_path)
                         return -ENOMEM;
 
                 r = sd_bus_message_append(reply, "(usssoo)",
-                                          list[i]->id,
-                                          list[i]->unit->id,
-                                          job_type_to_string(list[i]->type),
-                                          job_state_to_string(list[i]->state),
+                                          job->id,
+                                          job->unit->id,
+                                          job_type_to_string(job->type),
+                                          job_state_to_string(job->state),
                                           job_path,
                                           unit_path);
                 if (r < 0)
index 233e9c6b006896860316ed9b707d540434b2783b..6df4be8333b7efe845675bd914e352b749ce489c 100644 (file)
@@ -6,6 +6,7 @@
 #include "string-util.h"
 
 CompareOperator parse_compare_operator(const char **s, CompareOperatorParseFlags flags) {
+
         static const struct {
                 CompareOperator op;
                 const char *str;
@@ -40,19 +41,19 @@ CompareOperator parse_compare_operator(const char **s, CompareOperatorParseFlags
                   * parse_compare_operator() are use on the same string? */
                 return _COMPARE_OPERATOR_INVALID;
 
-        for (size_t i = 0; i < ELEMENTSOF(table); i++) {
+        FOREACH_ARRAY(i, table, ELEMENTSOF(table)) {
                 const char *e;
 
-                if (table[i].need_mask != 0 && !FLAGS_SET(flags, table[i].need_mask))
+                if (i->need_mask != 0 && !FLAGS_SET(flags, i->need_mask))
                         continue;
 
-                e = startswith(*s, table[i].str);
+                e = startswith(*s, i->str);
                 if (e) {
-                        if (table[i].valid_mask != 0 && !FLAGS_SET(flags, table[i].valid_mask))
+                        if (i->valid_mask != 0 && !FLAGS_SET(flags, i->valid_mask))
                                 return _COMPARE_OPERATOR_INVALID;
 
                         *s = e;
-                        return table[i].op;
+                        return i->op;
                 }
         }
 
index d9de2789a582317ee32681e10f6df72da2eedfa5..a602f6f1e2515950a31dd16e80088f09746b3ad8 100644 (file)
@@ -135,8 +135,8 @@ bool mount_point_is_api(const char *path) {
         /* Checks if this mount point is considered "API", and hence
          * should be ignored */
 
-        for (size_t i = 0; i < ELEMENTSOF(mount_table); i++)
-                if (path_equal(path, mount_table[i].where))
+        FOREACH_ARRAY(i, mount_table, ELEMENTSOF(mount_table))
+                if (path_equal(path, i->where))
                         return true;
 
         return path_startswith(path, "/sys/fs/cgroup/");