]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
use FOREACH_ELEMENT 32336/head
authorMatteo Croce <teknoraver@meta.com>
Thu, 18 Apr 2024 12:31:39 +0000 (14:31 +0200)
committerMatteo Croce <teknoraver@meta.com>
Thu, 18 Apr 2024 15:39:34 +0000 (17:39 +0200)
Use FOREACH_ELEMENT where possible. Generated with this command,
and checked manually:

    git grep -l 'FOREACH_ARRAY.*ELEMENTSOF' | \
    xargs sed -ri 's/FOREACH_ARRAY\((.*), (.*), (ELEMENTSOF.*)\)/FOREACH_ELEMENT(\1, \2)/'

26 files changed:
src/analyze/analyze-security.c
src/analyze/analyze-time-data.c
src/analyze/analyze-verify-util.c
src/core/cgroup.c
src/core/exec-invoke.c
src/core/kmod-setup.c
src/core/transaction.c
src/getty-generator/getty-generator.c
src/login/logind-action.c
src/login/logind-user.c
src/pcrlock/pcrlock.c
src/shared/bus-wait-for-jobs.c
src/shared/compare-operator.c
src/shared/dev-setup.c
src/shared/mount-setup.c
src/shared/sleep-config.c
src/shared/switch-root.c
src/shared/tpm2-util.c
src/shared/varlink.c
src/test/test-creds.c
src/test/test-mount-util.c
src/test/test-openssl.c
src/test/test-stat-util.c
src/test/test-tpm2.c
src/update-utmp/update-utmp.c
src/userdb/userdbctl.c

index 486143b7f0620dff04342940da9d2c06971f08c4..668475d1f573836ec529eb2f66917acd635fb5c0 100644 (file)
@@ -1756,7 +1756,7 @@ static int assess(const SecurityInfo *info,
                         (void) table_set_display(details_table, (size_t) 0, (size_t) 1, (size_t) 2, (size_t) 3, (size_t) 7);
         }
 
-        FOREACH_ARRAY(a, security_assessor_table, ELEMENTSOF(security_assessor_table)) {
+        FOREACH_ELEMENT(a, security_assessor_table) {
                 _cleanup_free_ char *d = NULL;
                 uint64_t badness;
                 void *data;
index 62e055dda4de7708701b2c6f4e2fe56cab3a0288..1a2699166f37225ec3bdc8125a650ad83c883923 100644 (file)
@@ -249,7 +249,7 @@ void unit_times_clear(UnitTimes *t) {
         if (!t)
                 return;
 
-        FOREACH_ARRAY(d, t->deps, ELEMENTSOF(t->deps))
+        FOREACH_ELEMENT(d, t->deps)
                 *d = strv_free(*d);
 
         t->name = mfree(t->name);
index 3e5adcab2ef0ad62b768cae65b53d0fb67e244a3..8e83c9a589b1707013a337e466bcd692686e323f 100644 (file)
@@ -202,12 +202,12 @@ static int verify_executables(Unit *u, const char *root) {
         assert(u);
 
         if (u->type == UNIT_SERVICE)
-                FOREACH_ARRAY(i, SERVICE(u)->exec_command, ELEMENTSOF(SERVICE(u)->exec_command))
+                FOREACH_ELEMENT(i, SERVICE(u)->exec_command)
                         LIST_FOREACH(command, j, *i)
                                 RET_GATHER(r, verify_executable(u, j, root));
 
         if (u->type == UNIT_SOCKET)
-                FOREACH_ARRAY(i, SOCKET(u)->exec_command, ELEMENTSOF(SOCKET(u)->exec_command))
+                FOREACH_ELEMENT(i, SOCKET(u)->exec_command)
                         LIST_FOREACH(command, j, *i)
                                 RET_GATHER(r, verify_executable(u, j, root));
 
index 852a16622f1108e689e014755c62de4dd44ec6a7..47f028fbe0711403cea34a3204fafc1c3badc4e3 100644 (file)
@@ -4918,7 +4918,7 @@ void unit_reset_memory_accounting_last(Unit *u) {
         if (!crt || !crt->cgroup_path)
                 return;
 
-        FOREACH_ARRAY(i, crt->memory_accounting_last, ELEMENTSOF(crt->memory_accounting_last))
+        FOREACH_ELEMENT(i, crt->memory_accounting_last)
                 *i = UINT64_MAX;
 }
 
@@ -5226,13 +5226,13 @@ CGroupRuntime *cgroup_runtime_new(void) {
                 .cgroup_invalidated_mask = _CGROUP_MASK_ALL,
         };
 
-        FOREACH_ARRAY(i, crt->memory_accounting_last, ELEMENTSOF(crt->memory_accounting_last))
+        FOREACH_ELEMENT(i, crt->memory_accounting_last)
                 *i = UINT64_MAX;
-        FOREACH_ARRAY(i, crt->io_accounting_base, ELEMENTSOF(crt->io_accounting_base))
+        FOREACH_ELEMENT(i, crt->io_accounting_base)
                 *i = UINT64_MAX;
-        FOREACH_ARRAY(i, crt->io_accounting_last, ELEMENTSOF(crt->io_accounting_last))
+        FOREACH_ELEMENT(i, crt->io_accounting_last)
                 *i = UINT64_MAX;
-        FOREACH_ARRAY(i, crt->ip_accounting_extra, ELEMENTSOF(crt->ip_accounting_extra))
+        FOREACH_ELEMENT(i, crt->ip_accounting_extra)
                 *i = UINT64_MAX;
 
         return TAKE_PTR(crt);
index 90e11d0d1e9c1fc419e53940b6c807013c677648..32b48ececc0d1f267fb260889e1e7d13f972f28d 100644 (file)
@@ -3717,7 +3717,7 @@ static int connect_unix_harder(const ExecContext *c, const ExecParameters *p, co
                 return log_exec_error_errno(c, p, r, "Failed to set sockaddr for '%s': %m", of->path);
         sa_len = r;
 
-        FOREACH_ARRAY(i, socket_types, ELEMENTSOF(socket_types)) {
+        FOREACH_ELEMENT(i, socket_types) {
                 _cleanup_close_ int fd = -EBADF;
 
                 fd = socket(AF_UNIX, *i|SOCK_CLOEXEC, 0);
index 3f8f7e3bca581af6b5500dc5c08cf55068a86215..c39b136e046076d7633fd8cd1312cc59c941366e 100644 (file)
@@ -157,7 +157,7 @@ int kmod_setup(void) {
                 return 0;
 
         _cleanup_(sym_kmod_unrefp) struct kmod_ctx *ctx = NULL;
-        FOREACH_ARRAY(kmod, kmod_table, ELEMENTSOF(kmod_table)) {
+        FOREACH_ELEMENT(kmod, kmod_table) {
                 if (kmod->path && access(kmod->path, F_OK) >= 0)
                         continue;
 
index b5c6348b6fcbc7bef2e7f5a6f94c05f788759174..d70a44b23c853a02132f87507a8d58b80b181a9a 100644 (file)
@@ -446,7 +446,7 @@ static int transaction_verify_order_one(Transaction *tr, Job *j, Job *from, unsi
          * the graph over 'before' edges in the actual job execution order. We traverse over both unit
          * ordering dependencies and we test with job_compare() whether it is the 'before' edge in the job
          * execution ordering. */
-        FOREACH_ARRAY(d, directions, ELEMENTSOF(directions)) {
+        FOREACH_ELEMENT(d, directions) {
                 Unit *u;
 
                 UNIT_FOREACH_DEPENDENCY(u, j->unit, *d) {
index 288f91cedf52716605c82facee5b53f8d5e9b515..acce71b1a88b19e70ef57b2b3f79c028954443ae 100644 (file)
@@ -150,7 +150,7 @@ static int add_credential_gettys(void) {
         };
         int r;
 
-        FOREACH_ARRAY(t, table, ELEMENTSOF(table)) {
+        FOREACH_ELEMENT(t, table) {
                 _cleanup_free_ char *b = NULL;
                 size_t sz = 0;
 
index c86856806b591cd2df6e7485a52ba0356a142b36..9325d91549d5e5ac88d169307819145726a4b05f 100644 (file)
@@ -156,7 +156,7 @@ int handle_action_get_enabled_sleep_actions(HandleActionSleepMask mask, char ***
 
         assert(ret);
 
-        FOREACH_ARRAY(i, sleep_actions, ELEMENTSOF(sleep_actions))
+        FOREACH_ELEMENT(i, sleep_actions)
                 if (FLAGS_SET(mask, 1U << *i)) {
                         r = strv_extend(&actions, handle_action_to_string(*i));
                         if (r < 0)
@@ -170,7 +170,7 @@ int handle_action_get_enabled_sleep_actions(HandleActionSleepMask mask, char ***
 HandleAction handle_action_sleep_select(Manager *m) {
         assert(m);
 
-        FOREACH_ARRAY(i, sleep_actions, ELEMENTSOF(sleep_actions)) {
+        FOREACH_ELEMENT(i, sleep_actions) {
                 HandleActionSleepMask action_mask = 1U << *i;
                 const HandleActionData *a;
                 _cleanup_free_ char *load_state = NULL;
index 537cc551cc0b379a0a2d8c980e6c134987068caf..1c2ac81353f4d927c41efcc391b65b99fc95e2f1 100644 (file)
@@ -469,7 +469,7 @@ static int user_update_slice(User *u) {
                 { "IOWeight",   u->user_record->io_weight   },
         };
 
-        FOREACH_ARRAY(st, settings, ELEMENTSOF(settings)) {
+        FOREACH_ELEMENT(st, settings) {
                 if (st->value == UINT64_MAX)
                         continue;
 
index 1fb9d692a276ad16c4c043b9ae3c28a5c75041b8..f6b76d291bcbd4fce76c9adb2df122c0fa49bde5 100644 (file)
@@ -2816,7 +2816,7 @@ static int verb_lock_secureboot_policy(int argc, char *argv[], void *userdata) {
         /* Generates expected records from the current SecureBoot state, as readable in the EFI variables
          * right now. */
 
-        FOREACH_ARRAY(vv, variables, ELEMENTSOF(variables)) {
+        FOREACH_ELEMENT(vv, variables) {
                 _cleanup_(json_variant_unrefp) JsonVariant *record = NULL;
 
                 _cleanup_free_ char *name = NULL;
index 2930552be486bb84afa84a3f53a417a6ae921a30..e12189f298be603479cdb7c45e3b75b97121731e 100644 (file)
@@ -187,7 +187,7 @@ static void log_job_error_with_service_result(const char* service, const char *r
         }
 
         if (!isempty(result))
-                FOREACH_ARRAY(i, explanations, ELEMENTSOF(explanations))
+                FOREACH_ELEMENT(i, explanations)
                         if (streq(result, i->result)) {
                                 log_error("Job for %s failed because %s.\n"
                                           "See \"%s status %s\" and \"%s -xeu %s\" for details.\n",
index 6df4be8333b7efe845675bd914e352b749ce489c..a13db8ee4fb6a9c736ba0e149adf73b888ed573c 100644 (file)
@@ -41,7 +41,7 @@ CompareOperator parse_compare_operator(const char **s, CompareOperatorParseFlags
                   * parse_compare_operator() are use on the same string? */
                 return _COMPARE_OPERATOR_INVALID;
 
-        FOREACH_ARRAY(i, table, ELEMENTSOF(table)) {
+        FOREACH_ELEMENT(i, table) {
                 const char *e;
 
                 if (i->need_mask != 0 && !FLAGS_SET(flags, i->need_mask))
index 3592b0a6505ade49dcde4715f61d275a91769e07..459e7279921f2c278d56ae83d4dbd37c8ac81f66 100644 (file)
@@ -119,7 +119,7 @@ int make_inaccessible_nodes(
          * to lock down these nodes as much as we can, but otherwise try to match them as closely as possible with the
          * underlying file, i.e. in the best case we offer the same node type as the underlying node. */
 
-        FOREACH_ARRAY(m, table, ELEMENTSOF(table)) {
+        FOREACH_ELEMENT(m, table) {
                 _cleanup_free_ char *path = NULL;
                 mode_t inode_type = *m;
                 const char *fn;
index 3c0132fd08653bbf60ad50c7c0463c539677159e..56381bc7d875ef5422aa63853e545fccde565fc6 100644 (file)
@@ -125,7 +125,7 @@ bool mount_point_is_api(const char *path) {
         /* Checks if this mount point is considered "API", and hence
          * should be ignored */
 
-        FOREACH_ARRAY(i, mount_table, ELEMENTSOF(mount_table))
+        FOREACH_ELEMENT(i, mount_table)
                 if (path_equal(path, i->where))
                         return true;
 
@@ -521,7 +521,7 @@ int mount_cgroup_legacy_controllers(bool loaded_policy) {
         if (!cg_is_legacy_force_enabled())
                 return -ERFKILL;
 
-        FOREACH_ARRAY(mp, cgroupv1_mount_table, ELEMENTSOF(cgroupv1_mount_table)) {
+        FOREACH_ELEMENT(mp, cgroupv1_mount_table) {
                 r = mount_one(mp, loaded_policy);
                 if (r < 0)
                         return r;
index b8cd83c7c1efb752be93de450b3b947f270cf4ce..aac145836b6c9f62072ef6476b5f71016836398d 100644 (file)
@@ -294,7 +294,7 @@ static int s2h_supported(const SleepConfig *sleep_config, SleepSupport *ret_supp
                 return false;
         }
 
-        FOREACH_ARRAY(i, operations, ELEMENTSOF(operations)) {
+        FOREACH_ELEMENT(i, operations) {
                 r = sleep_supported_internal(sleep_config, *i, /* check_allowed = */ false, &support);
                 if (r < 0)
                         return r;
index aba9d52e9677a950a8ffe02690e61a82ee569c28..cd87417a605d82442c6b1291957f5839adfb5732 100644 (file)
@@ -126,7 +126,7 @@ int switch_root(const char *new_root,
          * and switch_root() nevertheless. */
         (void) base_filesystem_create_fd(new_root_fd, new_root, UID_INVALID, GID_INVALID);
 
-        FOREACH_ARRAY(transfer, transfer_table, ELEMENTSOF(transfer_table)) {
+        FOREACH_ELEMENT(transfer, transfer_table) {
                 _cleanup_free_ char *chased = NULL;
                 unsigned long mount_flags;
 
index 42975cdb970e46bed36a055c51aedf6dcc181639..af2f265bab94ca15ebd366ec3ec1a9add7fff2e4 100644 (file)
@@ -4135,7 +4135,7 @@ static const struct {
 static int tpm2_ecc_curve_from_openssl_curve_id(int openssl_ecc_curve_id, TPM2_ECC_CURVE *ret) {
         assert(ret);
 
-        FOREACH_ARRAY(t, tpm2_openssl_ecc_curve_table, ELEMENTSOF(tpm2_openssl_ecc_curve_table))
+        FOREACH_ELEMENT(t, tpm2_openssl_ecc_curve_table)
                 if (t->openssl_ecc_curve_id == openssl_ecc_curve_id) {
                         *ret = t->tpm2_ecc_curve_id;
                         return 0;
@@ -4148,7 +4148,7 @@ static int tpm2_ecc_curve_from_openssl_curve_id(int openssl_ecc_curve_id, TPM2_E
 static int tpm2_ecc_curve_to_openssl_curve_id(TPM2_ECC_CURVE tpm2_ecc_curve_id, int *ret) {
         assert(ret);
 
-        FOREACH_ARRAY(t, tpm2_openssl_ecc_curve_table, ELEMENTSOF(tpm2_openssl_ecc_curve_table))
+        FOREACH_ELEMENT(t, tpm2_openssl_ecc_curve_table)
                 if (t->tpm2_ecc_curve_id == tpm2_ecc_curve_id) {
                         *ret = t->openssl_ecc_curve_id;
                         return 0;
index 713aff289597929523a85a810f17c4653eed2950..f1c00a21b61a2f92b4daa254d837e81d3e03505b 100644 (file)
@@ -4124,7 +4124,7 @@ int varlink_error_to_errno(const char *error, JsonVariant *parameters) {
         if (!error)
                 return 0;
 
-        FOREACH_ARRAY(t, table, ELEMENTSOF(table))
+        FOREACH_ELEMENT(t, table)
                 if (streq(error, t->error))
                         return t->value;
 
index 84619c91de92e9ed60656e661456212d1f0356c1..cc9cc7377821bfe2d95bdf5cf21db96cc69fddae 100644 (file)
@@ -243,7 +243,7 @@ TEST(mime_type_matches) {
         };
 
         /* Generates the right <match/> expressions for these credentials according to the shared mime-info spec */
-        FOREACH_ARRAY(t, tags, ELEMENTSOF(tags)) {
+        FOREACH_ELEMENT(t, tags) {
                 _cleanup_free_ char *encoded = NULL;
 
                 assert_se(base64mem(t, sizeof(sd_id128_t), &encoded) >= 0);
index a2711f059e393b6a1ccbc2f8f3fee039805d3dac..4f6da39f48e99b47d587463fdbe623f0112b1623 100644 (file)
@@ -305,7 +305,7 @@ TEST(make_mount_switch_root) {
                 { "/", true  },
         };
 
-        FOREACH_ARRAY(i, table, ELEMENTSOF(table)) {
+        FOREACH_ELEMENT(i, table) {
                 r = safe_fork("(switch-root)",
                               FORK_RESET_SIGNALS |
                               FORK_CLOSE_ALL_FDS |
@@ -358,7 +358,7 @@ TEST(umount_recursive) {
 
         int r;
 
-        FOREACH_ARRAY(t, test_table, ELEMENTSOF(test_table)) {
+        FOREACH_ELEMENT(t, test_table) {
 
                 r = safe_fork("(umount-rec)",
                               FORK_RESET_SIGNALS |
index 51dc492e965dee9bfb1155fe24d42066208983bb..d0ea0f0215570cf2a720baf304a3368735094e94 100644 (file)
@@ -136,7 +136,7 @@ static const struct {
 TEST(digest_size) {
         size_t size;
 
-        FOREACH_ARRAY(t, digest_size_table, ELEMENTSOF(digest_size_table)) {
+        FOREACH_ELEMENT(t, digest_size_table) {
                 assert(openssl_digest_size(t->alg, &size) >= 0);
                 assert_se(size == t->size);
 
index a69f6f06e0a7fda0dea6308c7dbc8974159d42fc..6f274c917c5ae17f6b36d56984d82a4a926044bf 100644 (file)
@@ -192,7 +192,7 @@ TEST(inode_type_from_string) {
                 S_IFSOCK,
         };
 
-        FOREACH_ARRAY(m, types, ELEMENTSOF(types))
+        FOREACH_ELEMENT(m, types)
                 assert_se(inode_type_from_string(inode_type_to_string(*m)) == *m);
 }
 
index 1a9c998818828c6eaefa6ef432e579b7112fcec0..3b5a375c883eeba43ccadf374598873a80a0cbd0 100644 (file)
@@ -1266,7 +1266,7 @@ static void check_seal_unseal(Tpm2Context *c) {
         check_seal_unseal_for_handle(c, 0);
         check_seal_unseal_for_handle(c, TPM2_SRK_HANDLE);
 
-        FOREACH_ARRAY(template, test_templates, ELEMENTSOF(test_templates)) {
+        FOREACH_ELEMENT(template, test_templates) {
                 TPM2B_PUBLIC public = {
                         .publicArea = **template,
                         .size = sizeof(**template),
index 4ee935e0441335914f6fb2c871543c75b7fde718..c376676e8d0a521ffea2e3a54d0029e6ee6ee0cc 100644 (file)
@@ -82,7 +82,7 @@ static int get_current_runlevel(Context *c) {
         assert(c);
 
         for (unsigned n_attempts = 0;;) {
-                FOREACH_ARRAY(e, table, ELEMENTSOF(table)) {
+                FOREACH_ELEMENT(e, table) {
                         _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
                         _cleanup_free_ char *state = NULL, *path = NULL;
 
index 918b4d772f28ea126783e0fad82945a2ff32880e..1718419407bc0089e379ef76174fd820f3eeb3dc 100644 (file)
@@ -174,7 +174,7 @@ static int table_add_uid_boundaries(Table *table, const UIDRange *p) {
 
         assert(table);
 
-        FOREACH_ARRAY(i, uid_range_table, ELEMENTSOF(uid_range_table)) {
+        FOREACH_ELEMENT(i, uid_range_table) {
                 _cleanup_free_ char *name = NULL, *comment = NULL;
 
                 if (!uid_range_covers(p, i->first, i->last - i->first + 1))
@@ -532,7 +532,7 @@ static int table_add_gid_boundaries(Table *table, const UIDRange *p) {
 
         assert(table);
 
-        FOREACH_ARRAY(i, uid_range_table, ELEMENTSOF(uid_range_table)) {
+        FOREACH_ELEMENT(i, uid_range_table) {
                 _cleanup_free_ char *name = NULL, *comment = NULL;
 
                 if (!uid_range_covers(p, i->first, i->last - i->first + 1))