]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
strv: declare iterator of FOREACH_STRING() in the loop
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 23 Mar 2022 09:48:13 +0000 (10:48 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 23 Mar 2022 10:50:18 +0000 (11:50 +0100)
Same idea as 03677889f0ef42cdc534bf3b31265a054b20a354.

No functional change intended. The type of the iterator is generally changed to
be 'const char*' instead of 'char*'. Despite the type commonly used, modifying
the string was not allowed.

I adjusted the naming of some short variables for clarity and reduced the scope
of some variable declarations in code that was being touched anyway.

53 files changed:
src/activate/activate.c
src/basic/fs-util.c
src/basic/os-util.c
src/basic/strv.h
src/basic/unit-file.c
src/boot/bootctl.c
src/cgtop/cgtop.c
src/core/apparmor-setup.c
src/core/cgroup.c
src/core/efi-random.c
src/core/execute.c
src/core/timer.c
src/core/unit.c
src/getty-generator/getty-generator.c
src/home/homectl.c
src/home/homed-manager.c
src/libsystemd/sd-device/sd-device.c
src/locale/localed.c
src/login/logind-user.c
src/nspawn/nspawn-cgroup.c
src/nspawn/nspawn-mount.c
src/nspawn/nspawn.c
src/partition/repart.c
src/portable/portable.c
src/resolve/resolved-resolv-conf.c
src/resolve/test-resolved-etc-hosts.c
src/run/run.c
src/shared/chown-recursive.c
src/shared/discover-image.c
src/shared/dissect-image.c
src/shared/find-esp.c
src/shared/machine-id-setup.c
src/shared/mount-setup.c
src/shared/netif-util.c
src/shared/pager.c
src/shared/psi-util.c
src/shared/switch-root.c
src/shared/tests.c
src/systemctl/systemctl-edit.c
src/systemctl/systemctl-sysv-compat.c
src/test/test-bpf-devices.c
src/test/test-ellipsize.c
src/test/test-env-file.c
src/test/test-execute.c
src/test/test-fileio.c
src/test/test-gpt.c
src/test/test-libcrypt-util.c
src/test/test-loop-block.c
src/test/test-mount-util.c
src/test/test-stat-util.c
src/test/test-strv.c
src/test/test-utf8.c
src/tmpfiles/offline-passwd.c

index d39a8b4415dfa0545ca739d41d5b7293ed460023..8ee7a3ec60128572bb8ce09748d5a9f2230a7d98 100644 (file)
@@ -123,7 +123,6 @@ static int open_sockets(int *epoll_fd, bool accept) {
 
 static int exec_process(const char *name, char **argv, int start_fd, size_t n_fds) {
         _cleanup_strv_free_ char **envp = NULL;
-        const char *var;
         int r;
 
         if (arg_inetd && n_fds != 1)
index e7e8ee236bc2825fe387f3a368578613e81bb615..4c81057a8974a36f0019f181cf96fe94d883d657 100644 (file)
@@ -570,7 +570,6 @@ int get_files_in_directory(const char *path, char ***list) {
 }
 
 static int getenv_tmp_dir(const char **ret_path) {
-        const char *n;
         int r, ret = 0;
 
         assert(ret_path);
index ee3a2114993c505c8db7528160423f3062467fdc..bf86f6434845b804d12b1d7864b1bbf3306977a7 100644 (file)
@@ -170,8 +170,6 @@ int open_extension_release(const char *root, const char *extension, char **ret_p
                         }
                 }
         } else {
-                const char *p;
-
                 FOREACH_STRING(p, "/etc/os-release", "/usr/lib/os-release") {
                         r = chase_symlinks(p, root, CHASE_PREFIX_ROOT,
                                            ret_path ? &q : NULL,
index bc76a2861cb322cc33bbfe5d42cabdeb21d2e3cd..c89c0f64e27078032e3ddd910b03d18739a7c5f2 100644 (file)
@@ -218,7 +218,7 @@ void strv_print(char * const *l);
         })
 
 #define _FOREACH_STRING(uniq, x, y, ...)                                \
-        for (char **UNIQ_T(l, uniq) = STRV_MAKE(({ x = y; }), ##__VA_ARGS__); \
+        for (const char *x, * const*UNIQ_T(l, uniq) = STRV_MAKE_CONST(({ x = y; }), ##__VA_ARGS__); \
              x;                                                         \
              x = *(++UNIQ_T(l, uniq)))
 
index c2512dc9abe2d78337ec8a408d3e944a5281fb05..d44b88644099d21e406342f6d69e7d604e9a62dc 100644 (file)
@@ -236,7 +236,6 @@ bool lookup_paths_timestamp_hash_same(const LookupPaths *lp, uint64_t timestamp_
 }
 
 static int directory_name_is_valid(const char *name) {
-        const char *suffix;
 
         /* Accept a directory whose name is a valid unit file name ending in .wants/, .requires/ or .d/ */
 
index 8103a1cf097f7115162d5df169a2ab09830bd1e0..5dd92a6ca0f2a9abdfee02232221760cb1fe3b00 100644 (file)
@@ -1255,12 +1255,11 @@ static int remove_variables(sd_id128_t uuid, const char *path, bool in_order) {
 }
 
 static int remove_loader_variables(void) {
-        const char *variable;
         int r = 0;
 
         /* Remove all persistent loader variables we define */
 
-        FOREACH_STRING(variable,
+        FOREACH_STRING(var,
                        EFI_LOADER_VARIABLE(LoaderConfigTimeout),
                        EFI_LOADER_VARIABLE(LoaderConfigTimeoutOneShot),
                        EFI_LOADER_VARIABLE(LoaderEntryDefault),
@@ -1269,15 +1268,15 @@ static int remove_loader_variables(void) {
 
                 int q;
 
-                q = efi_set_variable(variable, NULL, 0);
+                q = efi_set_variable(var, NULL, 0);
                 if (q == -ENOENT)
                         continue;
                 if (q < 0) {
-                        log_warning_errno(q, "Failed to remove EFI variable %s: %m", variable);
+                        log_warning_errno(q, "Failed to remove EFI variable %s: %m", var);
                         if (r >= 0)
                                 r = q;
                 } else
-                        log_info("Removed EFI variable %s.", variable);
+                        log_info("Removed EFI variable %s.", var);
         }
 
         return r;
index e5ab904c4fc0d4ad185705e047a59ce7f1b9aa81..b023e717573e72b1e5cf5a4e2181d39068ae9640 100644 (file)
@@ -510,7 +510,6 @@ static int refresh_one(
 }
 
 static int refresh(const char *root, Hashmap *a, Hashmap *b, unsigned iteration) {
-        const char *c;
         int r;
 
         FOREACH_STRING(c, SYSTEMD_CGROUP_CONTROLLER, "cpu", "cpuacct", "memory", "io", "blkio", "pids") {
index 304a3e6aac21393ac14a2def21311f249a9bb178..3426a10358898d5de69de71e7d79ad52b91b2cf4 100644 (file)
@@ -24,7 +24,6 @@ int mac_apparmor_setup(void) {
 #if HAVE_APPARMOR
         _cleanup_(aa_policy_cache_unrefp) aa_policy_cache *policy_cache = NULL;
         _cleanup_(aa_features_unrefp) aa_features *features = NULL;
-        const char *current_file;
         _cleanup_free_ char *current_profile = NULL, *cache_dir_path = NULL;
         int r;
 
index 15ab363548ac900a018ae5f1c386c1d69c1890a8..42055e4e418ae701b5dbc0dfa60a2eccab7235b7 100644 (file)
@@ -786,7 +786,6 @@ void cgroup_oomd_xattr_apply(Unit *u, const char *cgroup_path) {
 }
 
 static void cgroup_xattr_apply(Unit *u) {
-        const char *xn;
         bool b;
 
         assert(u);
index a0b89d137948b3ca632cd76cc3dfa5ae9bdd3f60..e8d8ccd117518f74235d47980b7d464aa5c3bca4 100644 (file)
  * is suitably validated. */
 
 static void lock_down_efi_variables(void) {
-        const char *p;
         int r;
 
         /* Paranoia: let's restrict access modes of these a bit, so that unprivileged users can't use them to
          * identify the system or gain too much insight into what we might have credited to the entropy
          * pool. */
-        FOREACH_STRING(p,
+        FOREACH_STRING(path,
                        EFIVAR_PATH(EFI_LOADER_VARIABLE(LoaderRandomSeed)),
                        EFIVAR_PATH(EFI_LOADER_VARIABLE(LoaderSystemToken))) {
 
-                r = chattr_path(p, 0, FS_IMMUTABLE_FL, NULL);
+                r = chattr_path(path, 0, FS_IMMUTABLE_FL, NULL);
                 if (r == -ENOENT)
                         continue;
                 if (r < 0)
-                        log_warning_errno(r, "Failed to drop FS_IMMUTABLE_FL from %s, ignoring: %m", p);
+                        log_warning_errno(r, "Failed to drop FS_IMMUTABLE_FL from %s, ignoring: %m", path);
 
-                if (chmod(p, 0600) < 0)
-                        log_warning_errno(errno, "Failed to reduce access mode of %s, ignoring: %m", p);
+                if (chmod(path, 0600) < 0)
+                        log_warning_errno(errno, "Failed to reduce access mode of %s, ignoring: %m", path);
         }
 }
 
index 8652e339239d06c3b6d74181abdbdbb116d3b18d..3cd63846b508713ec93f7bea9518e030807e7db4 100644 (file)
@@ -3043,7 +3043,6 @@ static int setup_credentials(
                 uid_t uid) {
 
         _cleanup_free_ char *p = NULL, *q = NULL;
-        const char *i;
         int r;
 
         assert(context);
index 69a4ea652a8569946b48d0c75091abb8d343a1f7..ab107860a7e451c1cb451ec281bda8fb1b858bb3 100644 (file)
@@ -99,8 +99,6 @@ static int timer_add_default_dependencies(Timer *t) {
                         return r;
 
                 LIST_FOREACH(value, v, t->values) {
-                        const char *target;
-
                         if (v->base != TIMER_CALENDAR)
                                 continue;
 
index 42fb4220f60436b8264296a65c7f84982afa976b..5ab7601ed86dab0cfc3a931c230a700816e1f0e7 100644 (file)
@@ -4133,7 +4133,6 @@ int unit_patch_contexts(Unit *u) {
 
                 if ((ec->root_image || !LIST_IS_EMPTY(ec->mount_images)) &&
                     (cc->device_policy != CGROUP_DEVICE_POLICY_AUTO || cc->device_allow)) {
-                        const char *p;
 
                         /* When RootImage= or MountImages= is specified, the following devices are touched. */
                         FOREACH_STRING(p, "/dev/loop-control", "/dev/mapper/control") {
index 59bdfc496b6b45e1a5cb0b0572d9dee908b67c27..4e8162a319871444c109e27ac993d8b55072effc 100644 (file)
@@ -215,9 +215,7 @@ static int run(const char *dest, const char *dest_early, const char *dest_late)
                         return r;
         }
 
-        /* Automatically add in a serial getty on the first
-         * virtualizer console */
-        const char *j;
+        /* Automatically add in a serial getty on the first virtualizer console */
         FOREACH_STRING(j,
                        "hvc0",
                        "xvc0",
index 671d5f5130eb6673dc0e75ede85c877cd5752db3..f0d1dac6ab0eda260886b929e526c481cc4524e1 100644 (file)
@@ -2949,8 +2949,6 @@ static int parse_argv(int argc, char *argv[]) {
 
                 case ARG_DISK_SIZE:
                         if (isempty(optarg)) {
-                                const char *prop;
-
                                 FOREACH_STRING(prop, "diskSize", "diskSizeRelative", "rebalanceWeight") {
                                         r = drop_from_identity(prop);
                                         if (r < 0)
@@ -3452,9 +3450,7 @@ static int parse_argv(int argc, char *argv[]) {
                         break;
                 }
 
-                case ARG_PKCS11_TOKEN_URI: {
-                        const char *p;
-
+                case ARG_PKCS11_TOKEN_URI:
                         if (streq(optarg, "list"))
                                 return pkcs11_list_tokens();
 
@@ -3488,11 +3484,8 @@ static int parse_argv(int argc, char *argv[]) {
 
                         strv_uniq(arg_pkcs11_token_uri);
                         break;
-                }
-
-                case ARG_FIDO2_DEVICE: {
-                        const char *p;
 
+                case ARG_FIDO2_DEVICE:
                         if (streq(optarg, "list"))
                                 return fido2_list_devices();
 
@@ -3522,7 +3515,6 @@ static int parse_argv(int argc, char *argv[]) {
 
                         strv_uniq(arg_fido2_device);
                         break;
-                }
 
                 case ARG_FIDO2_WITH_PIN: {
                         bool lock_with_pin;
@@ -3557,9 +3549,7 @@ static int parse_argv(int argc, char *argv[]) {
                         break;
                 }
 
-                case ARG_RECOVERY_KEY: {
-                        const char *p;
-
+                case ARG_RECOVERY_KEY:
                         r = parse_boolean(optarg);
                         if (r < 0)
                                 return log_error_errno(r, "Failed to parse --recovery-key= argument: %s", optarg);
@@ -3573,7 +3563,6 @@ static int parse_argv(int argc, char *argv[]) {
                         }
 
                         break;
-                }
 
                 case ARG_AUTO_RESIZE_MODE:
                         if (isempty(optarg)) {
index 9ed1348592f91fc084bfcf49fea61352dfeb2654..c2b9eb64f9bd0d23b6475e1d688842c74ef8ae0e 100644 (file)
@@ -482,7 +482,6 @@ static int manager_enumerate_records(Manager *m) {
 static int search_quota(uid_t uid, const char *exclude_quota_path) {
         struct stat exclude_st = {};
         dev_t previous_devno = 0;
-        const char *where;
         int r;
 
         /* Checks whether the specified UID owns any files on the files system, but ignore any file system
index a2fb34f9a11f0ae34dacd4175ee8b4b6b4a0814a..a58877e11eeec75d6f5daa3c5ab0ba339e4bc91d 100644 (file)
@@ -332,7 +332,6 @@ _public_ int sd_device_new_from_subsystem_sysname(
                 const char *subsystem,
                 const char *sysname) {
 
-        const char *s;
         char *name;
         int r;
 
@@ -341,7 +340,6 @@ _public_ int sd_device_new_from_subsystem_sysname(
         assert_return(path_is_normalized(sysname), -EINVAL);
 
         if (streq(subsystem, "subsystem")) {
-
                 FOREACH_STRING(s, "/sys/subsystem/", "/sys/bus/", "/sys/class/") {
                         r = device_strjoin_new(s, sysname, NULL, NULL, ret);
                         if (r < 0)
@@ -351,7 +349,6 @@ _public_ int sd_device_new_from_subsystem_sysname(
                 }
 
         } else  if (streq(subsystem, "module")) {
-
                 r = device_strjoin_new("/sys/module/", sysname, NULL, NULL, ret);
                 if (r < 0)
                         return r;
@@ -363,9 +360,8 @@ _public_ int sd_device_new_from_subsystem_sysname(
 
                 sep = strchr(sysname, ':');
                 if (sep && sep[1] != '\0') { /* Require ":" and something non-empty after that. */
-                        const char *subsys;
 
-                        subsys = memdupa_suffix0(sysname, sep - sysname);
+                        const char *subsys = memdupa_suffix0(sysname, sep - sysname);
                         sep++;
 
                         FOREACH_STRING(s, "/sys/subsystem/", "/sys/bus/") {
index 5d95da15600b1aabb0a42f05253e1d42b0426d6b..89bf9c6fbad5d7c1dd8eaae64ca1c93be5212380 100644 (file)
@@ -474,7 +474,7 @@ static int method_set_locale(sd_bus_message *m, void *userdata, sd_bus_error *er
 
 static int method_set_vc_keyboard(sd_bus_message *m, void *userdata, sd_bus_error *error) {
         Context *c = userdata;
-        const char *name, *keymap, *keymap_toggle;
+        const char *keymap, *keymap_toggle;
         int convert, interactive, r;
 
         assert(m);
index af33bf7a4f77c0348e605456f1951e3f4c476218..1312878718a29b844a8626eb1b0d43724bbe428e 100644 (file)
@@ -627,7 +627,6 @@ int user_check_linger_file(User *u) {
 }
 
 static bool user_unit_active(User *u) {
-        const char *i;
         int r;
 
         assert(u->service);
index af00119c2108de50d88d49790a9132386c1c6add..9e6379ae7b2ecb8e7dd0169caf0618623b2bf5a8 100644 (file)
@@ -22,7 +22,6 @@
 
 static int chown_cgroup_path(const char *path, uid_t uid_shift) {
         _cleanup_close_ int fd = -1;
-        const char *fn;
 
         fd = open(path, O_RDONLY|O_CLOEXEC|O_DIRECTORY);
         if (fd < 0)
index 7101a87694747f7c27f2b8f764b826178fe973e6..6378e1b703e6d3bcffc8c7bdf08602431b1c949a 100644 (file)
@@ -404,7 +404,7 @@ int tmpfs_patch_options(
 }
 
 int mount_sysfs(const char *dest, MountSettingsMask mount_settings) {
-        const char *full, *top, *x;
+        const char *full, *top;
         int r;
         unsigned long extra_flags = 0;
 
@@ -464,7 +464,7 @@ int mount_sysfs(const char *dest, MountSettingsMask mount_settings) {
         /* Create mountpoint for cgroups. Otherwise we are not allowed since we
          * remount /sys read-only.
          */
-        x = prefix_roota(top, "/fs/cgroup");
+        const char *x = prefix_roota(top, "/fs/cgroup");
         (void) mkdir_p(x, 0755);
 
         return mount_nofollow_verbose(LOG_ERR, NULL, top, NULL,
index 7fab88b31a88fd755bddb6e4230008953b726b42..e4c46866a072eee4a2dc7afccfef11c49aaa5ff0 100644 (file)
@@ -2564,7 +2564,7 @@ static int setup_hostname(void) {
 
 static int setup_journal(const char *directory) {
         _cleanup_free_ char *d = NULL;
-        const char *dirname, *p, *q;
+        const char *p, *q;
         sd_id128_t this_id;
         bool try;
         int r;
@@ -3512,7 +3512,6 @@ static int inner_child(
         (void) fdset_close_others(fds);
 
         if (arg_start_mode == START_BOOT) {
-                const char *init;
                 char **a;
                 size_t m;
 
@@ -4603,7 +4602,7 @@ static int load_settings(void) {
         _cleanup_(settings_freep) Settings *settings = NULL;
         _cleanup_fclose_ FILE *f = NULL;
         _cleanup_free_ char *p = NULL;
-        const char *fn, *i;
+        const char *fn;
         int r;
 
         if (arg_oci_bundle)
index 600c4f6e5b132c58fb17073ce81418d99a870c8d..118ab6c7d08bf21c898283529c6d694029d4e9c1 100644 (file)
@@ -4533,9 +4533,8 @@ static int acquire_root_devno(
 }
 
 static int find_root(char **ret, int *ret_fd) {
-        const char *p;
-        int r;
         _cleanup_free_ char *device = NULL;
+        int r;
 
         assert(ret);
         assert(ret_fd);
index a07a95a229f47882cb59307f1cdfc7ce5173b041..691aad5238d609d0c566f64743aeadf40182b2d2 100644 (file)
@@ -1599,7 +1599,6 @@ int portable_detach(
 
         SET_FOREACH(item, unit_files) {
                 _cleanup_free_ char *md = NULL;
-                const char *suffix;
 
                 if (unlinkat(dirfd(d), item, 0) < 0) {
                         log_debug_errno(errno, "Can't remove unit file %s/%s: %m", where, item);
index f6deb2cf4602cf2df3f0b1f260ec87e66e28fd94..5749aa1dc3e08832e832d66e085a50a552b2779e 100644 (file)
@@ -50,8 +50,6 @@ int manager_check_resolv_conf(const Manager *m) {
 }
 
 static bool file_is_our_own(const struct stat *st) {
-        const char *path;
-
         assert(st);
 
         FOREACH_STRING(path,
index e5a20a2b14794224fb0401d2213be888746d9740..d6cd184b5e2d8ed4fec6d757745fae8112964a79 100644 (file)
@@ -41,7 +41,6 @@ TEST(parse_etc_hosts) {
 
         int fd;
         _cleanup_fclose_ FILE *f;
-        const char *s;
 
         fd = mkostemp_safe(t);
         assert_se(fd >= 0);
index e75b027542f18e3fc0df73df0c8881f17c10c369..2ae629f595861354bac0d4e8662bd5e34781dd54 100644 (file)
@@ -1702,8 +1702,6 @@ static int start_transient_trigger(
 }
 
 static bool shall_make_executable_absolute(void) {
-        const char *f;
-
         if (strv_isempty(arg_cmdline))
                 return false;
         if (arg_transport != BUS_TRANSPORT_LOCAL)
index 7c9a3050b4c739ef91899076fd4c789f3fc426d9..05a7a10ce411367e61f150f20d99cb62d4010daf 100644 (file)
@@ -21,7 +21,6 @@ static int chown_one(
                 gid_t gid,
                 mode_t mask) {
 
-        const char *n;
         int r;
 
         assert(fd >= 0);
index 024ffb3248e181629d2adcaee16454927e7709c6..3f1644ea859949fb7e9a7f8ab6ea35233ccb0262 100644 (file)
@@ -85,7 +85,7 @@ DEFINE_HASH_OPS_WITH_VALUE_DESTRUCTOR(image_hash_ops, char, string_hash_func, st
 
 static char **image_settings_path(Image *image) {
         _cleanup_strv_free_ char **l = NULL;
-        const char *fn, *s;
+        const char *fn;
         unsigned i = 0;
 
         assert(image);
index 8a3da1f650810c4e0a60c0ea736b79c689510c1c..f4756bf8c589d09e94836170d09f163e470ae5c9 100644 (file)
@@ -3041,7 +3041,6 @@ int dissected_image_acquire_metadata(DissectedImage *m, DissectImageFlags extra_
 
                         case META_HAS_INIT_SYSTEM: {
                                 bool found = false;
-                                const char *init;
 
                                 FOREACH_STRING(init,
                                                "/usr/lib/systemd/systemd",  /* systemd on /usr merged system */
index 1569b46bdfeb24000c48e24c8a3055e6cbb8e722..fca24329d4dcbdf93c812fc093072a540f3708c3 100644 (file)
@@ -435,7 +435,8 @@ int find_esp_and_warn(
                 goto found;
         }
 
-        FOREACH_STRING(path, "/efi", "/boot", "/boot/efi") {
+        FOREACH_STRING(_path, "/efi", "/boot", "/boot/efi") {
+                path = _path;
 
                 r = verify_esp(path, /* searching= */ true, unprivileged_mode, ret_part, ret_pstart, ret_psize, ret_uuid, ret_devid);
                 if (r >= 0)
index e483675a75c2186e487da51eaca4483acee1ff1a..df4ac419cbb3a55a1ad68bfb829f37d9d46df316 100644 (file)
@@ -197,7 +197,7 @@ finish:
 
 int machine_id_commit(const char *root) {
         _cleanup_close_ int fd = -1, initial_mntns_fd = -1;
-        const char *etc_machine_id, *sync_path;
+        const char *etc_machine_id;
         sd_id128_t id;
         int r;
 
index eb6dac32e198cf2f69746e05c6527cf241365a59..975c027f47c9c067626b52806a8edf522db77021 100644 (file)
@@ -126,9 +126,6 @@ bool mount_point_is_api(const char *path) {
 }
 
 bool mount_point_ignore(const char *path) {
-
-        const char *i;
-
         /* These are API file systems that might be mounted by other software, we just list them here so that
          * we know that we should ignore them. */
         FOREACH_STRING(i,
@@ -515,7 +512,6 @@ int mount_setup(bool loaded_policy, bool leave_propagation) {
          * use the same label for all their files. */
         if (loaded_policy) {
                 usec_t before_relabel, after_relabel;
-                const char *i;
                 int n_extra;
 
                 before_relabel = now(CLOCK_MONOTONIC);
index 69d7cc2b10dd38bc5fee9382900c3c6f22004573..f56c5646c100002568c7b1fade8eb8b9a846bd9d 100644 (file)
@@ -54,14 +54,15 @@ int net_get_type_string(sd_device *device, uint16_t iftype, char **ret) {
 }
 
 const char *net_get_persistent_name(sd_device *device) {
-        const char *name, *field;
-
         assert(device);
 
         /* fetch some persistent data unique (on this machine) to this device */
-        FOREACH_STRING(field, "ID_NET_NAME_ONBOARD", "ID_NET_NAME_SLOT", "ID_NET_NAME_PATH", "ID_NET_NAME_MAC")
+        FOREACH_STRING(field, "ID_NET_NAME_ONBOARD", "ID_NET_NAME_SLOT", "ID_NET_NAME_PATH", "ID_NET_NAME_MAC") {
+                const char *name;
+
                 if (sd_device_get_property_value(device, field, &name) >= 0)
                         return name;
+        }
 
         return NULL;
 }
index 9426d3ef988ef7fb6f2c1c33c66787e997fa3a94..1a93deb628488ad7caa9f4fa6f6eb4600d91d59b 100644 (file)
@@ -144,7 +144,7 @@ void pager_open(PagerFlags flags) {
         if (r < 0)
                 return;
         if (r == 0) {
-                const char *less_charset, *exe;
+                const char *less_charset;
 
                 /* In the child start the pager */
 
index 009095e8c3b284b196e40fd95e8046ce346fe3ea..8bdd0d4a859ad33821ad8384c9db57ebc87bec76 100644 (file)
@@ -106,8 +106,6 @@ int read_resource_pressure(const char *path, PressureType type, ResourcePressure
 }
 
 int is_pressure_supported(void) {
-        const char *p;
-
         /* The pressure files, both under /proc and in cgroups, will exist
          * even if the kernel has PSI support disabled; we have to read
          * the file to make sure it doesn't return -EOPNOTSUPP */
index 99cd574197305bf48b1be532a0e32c4cdc3bddf7..1a444841fa0870a0774548cb9f422cb69d49f0bc 100644 (file)
@@ -33,7 +33,6 @@ int switch_root(const char *new_root,
         _cleanup_free_ char *resolved_old_root_after = NULL;
         _cleanup_close_ int old_root_fd = -1;
         bool old_root_remove;
-        const char *i;
         int r;
 
         assert(new_root);
@@ -64,12 +63,12 @@ int switch_root(const char *new_root,
         if (mount(NULL, "/", NULL, MS_REC|MS_PRIVATE, NULL) < 0)
                 return log_error_errno(errno, "Failed to set \"/\" mount propagation to private: %m");
 
-        FOREACH_STRING(i, "/sys", "/dev", "/run", "/proc") {
+        FOREACH_STRING(path, "/sys", "/dev", "/run", "/proc") {
                 _cleanup_free_ char *chased = NULL;
 
-                r = chase_symlinks(i, new_root, CHASE_PREFIX_ROOT|CHASE_NONEXISTENT, &chased, NULL);
+                r = chase_symlinks(path, new_root, CHASE_PREFIX_ROOT|CHASE_NONEXISTENT, &chased, NULL);
                 if (r < 0)
-                        return log_error_errno(r, "Failed to resolve %s/%s: %m", new_root, i);
+                        return log_error_errno(r, "Failed to resolve %s/%s: %m", new_root, path);
                 if (r > 0) {
                         /* Already exists. Let's see if it is a mount point already. */
                         r = path_is_mount_point(chased, NULL, 0);
@@ -81,8 +80,8 @@ int switch_root(const char *new_root,
                          /* Doesn't exist yet? */
                         (void) mkdir_p_label(chased, 0755);
 
-                if (mount(i, chased, NULL, mount_flags, NULL) < 0)
-                        return log_error_errno(errno, "Failed to mount %s to %s: %m", i, chased);
+                if (mount(path, chased, NULL, mount_flags, NULL) < 0)
+                        return log_error_errno(errno, "Failed to mount %s to %s: %m", path, chased);
         }
 
         /* Do not fail if base_filesystem_create() fails. Not all switch roots are like base_filesystem_create() wants
index e0a1409e3a4fadcdbec04ccf539542b0c11be812..a624fd7d10c2e84ff8ce2df53c3505ef00d53f9d 100644 (file)
@@ -306,16 +306,15 @@ const char *ci_environment(void) {
          * just the general CI environment type, but also whether we're sanitizing or not, etc. The caller is
          * expected to use strstr on the returned value. */
         static const char *ans = POINTER_MAX;
-        const char *p;
         int r;
 
         if (ans != POINTER_MAX)
                 return ans;
 
         /* We allow specifying the environment with $CITYPE. Nobody uses this so far, but we are ready. */
-        p = getenv("CITYPE");
-        if (!isempty(p))
-                return (ans = p);
+        const char *citype = getenv("CITYPE");
+        if (!isempty(citype))
+                return (ans = citype);
 
         if (getenv_bool("TRAVIS") > 0)
                 return (ans = "travis");
@@ -326,12 +325,12 @@ const char *ci_environment(void) {
         if (getenv("AUTOPKGTEST_ARTIFACTS") || getenv("AUTOPKGTEST_TMP"))
                 return (ans = "autopkgtest");
 
-        FOREACH_STRING(p, "CI", "CONTINOUS_INTEGRATION") {
+        FOREACH_STRING(var, "CI", "CONTINOUS_INTEGRATION") {
                 /* Those vars are booleans according to Semaphore and Travis docs:
                  * https://docs.travis-ci.com/user/environment-variables/#default-environment-variables
                  * https://docs.semaphoreci.com/ci-cd-environment/environment-variables/#ci
                  */
-                r = getenv_bool(p);
+                r = getenv_bool(var);
                 if (r > 0)
                         return (ans = "unknown"); /* Some other unknown thing */
                 if (r == 0)
index e18a32190f939ec88b3c4952b3d52239c224fab4..e24cfb2f454ba4dbf67b0dc572054aba40e9561c 100644 (file)
@@ -318,7 +318,7 @@ static int run_editor(char **paths) {
         if (r == 0) {
                 char **editor_args = NULL;
                 size_t n_editor_args = 0, i = 1, argc;
-                const char **args, *editor, *p;
+                const char **args, *editor;
 
                 argc = strv_length(paths)/2 + 1;
 
@@ -356,9 +356,9 @@ static int run_editor(char **paths) {
                 if (n_editor_args > 0)
                         execvp(args[0], (char* const*) args);
 
-                FOREACH_STRING(p, "editor", "nano", "vim", "vi") {
-                        args[0] = p;
-                        execvp(p, (char* const*) args);
+                FOREACH_STRING(name, "editor", "nano", "vim", "vi") {
+                        args[0] = name;
+                        execvp(name, (char* const*) args);
                         /* We do not fail if the editor doesn't exist because we want to try each one of them
                          * before failing. */
                         if (errno != ENOENT) {
index a78fa1e04ca08bbaf6f18fc3a0d32ba9ac64fcb9..017dba20340e74e1e5a44ed440aa8fa6ac35a4d0 100644 (file)
@@ -18,9 +18,8 @@
 
 int talk_initctl(char rl) {
 #if HAVE_SYSV_COMPAT
-        struct init_request request;
         _cleanup_close_ int fd = -1;
-        const char *p;
+        const char *path;
         int r;
 
         /* Try to switch to the specified SysV runlevel. Returns == 0 if the operation does not apply on this
@@ -29,19 +28,19 @@ int talk_initctl(char rl) {
         if (rl == 0)
                 return 0;
 
-        FOREACH_STRING(p, "/run/initctl", "/dev/initctl") {
-                fd = open(p, O_WRONLY|O_NONBLOCK|O_CLOEXEC|O_NOCTTY);
-                if (fd >= 0 || errno != ENOENT)
-                        break;
-        }
-        if (fd < 0) {
-                if (errno == ENOENT)
-                        return 0;
+        FOREACH_STRING(_path, "/run/initctl", "/dev/initctl") {
+                path = _path;
 
-                return log_error_errno(errno, "Failed to open initctl fifo: %m");
+                fd = open(path, O_WRONLY|O_NONBLOCK|O_CLOEXEC|O_NOCTTY);
+                if (fd < 0 && errno != ENOENT)
+                        return log_error_errno(errno, "Failed to open %s: %m", path);
+                if (fd >= 0)
+                        break;
         }
+        if (fd < 0)
+                return 0;
 
-        request = (struct init_request) {
+        struct init_request request = {
                 .magic = INIT_MAGIC,
                 .sleeptime = 0,
                 .cmd = INIT_CMD_RUNLVL,
@@ -50,7 +49,7 @@ int talk_initctl(char rl) {
 
         r = loop_write(fd, &request, sizeof(request), false);
         if (r < 0)
-                return log_error_errno(r, "Failed to write to %s: %m", p);
+                return log_error_errno(r, "Failed to write to %s: %m", path);
 
         return 1;
 #else
index bbaa7b3605e3000dc1b2789128f2e20a57880e02..587591cf04858adbe90c34b16cde332b9ca6814e 100644 (file)
@@ -30,7 +30,6 @@ static void test_policy_closed(const char *cgroup_path, BPFProgram **installed_p
         r = bpf_devices_apply_policy(&prog, CGROUP_DEVICE_POLICY_CLOSED, true, cgroup_path, installed_prog);
         assert_se(r >= 0);
 
-        const char *s;
         FOREACH_STRING(s, "/dev/null",
                           "/dev/zero",
                           "/dev/full",
index b840355f5e7203d8d4d26f8ccf1945465669273b..7317193363ac76ae490480e039b52563969391c1 100644 (file)
@@ -64,18 +64,14 @@ static void test_ellipsize_mem_one(const char *s, size_t old_length, size_t new_
 }
 
 TEST(ellipsize_mem) {
-        const char *s;
-        ssize_t l, k;
-
         FOREACH_STRING(s,
                        "_XXXXXXXXXXX_", /* ASCII */
                        "_aąęółśćńżźć_", /* two-byte utf-8 */
                        "გამარჯობა",     /* multi-byte utf-8 */
                        "你好世界",       /* wide characters */
                        "你გą世óoó界")    /* a mix */
-
-                for (l = strlen(s); l >= 0; l--)
-                        for (k = strlen(s) + 1; k >= 0; k--)
+                for (ssize_t l = strlen(s); l >= 0; l--)
+                        for (ssize_t k = strlen(s) + 1; k >= 0; k--)
                                 test_ellipsize_mem_one(s, l, k);
 }
 
index 7b132447bf36b4cad6c8a69b0f1e24509cd65ef9..f97206b4d6508fda1449f80753b0607d7826f78c 100644 (file)
@@ -166,8 +166,6 @@ TEST(load_env_file_6) {
 }
 
 TEST(write_and_load_env_file) {
-        const char *v;
-
         /* Make sure that our writer, parser and the shell agree on what our env var files mean */
 
         FOREACH_STRING(v,
index a2758b3f8418e2d1ecda0538b45359373e4ad49c..ba1be2b4531cfc11075a618503d9453d8fb6b722 100644 (file)
@@ -190,19 +190,15 @@ static bool check_user_has_group_with_same_name(const char *name) {
 }
 
 static bool is_inaccessible_available(void) {
-        const char *p;
-
         FOREACH_STRING(p,
-                "/run/systemd/inaccessible/reg",
-                "/run/systemd/inaccessible/dir",
-                "/run/systemd/inaccessible/chr",
-                "/run/systemd/inaccessible/blk",
-                "/run/systemd/inaccessible/fifo",
-                "/run/systemd/inaccessible/sock"
-        ) {
+                       "/run/systemd/inaccessible/reg",
+                       "/run/systemd/inaccessible/dir",
+                       "/run/systemd/inaccessible/chr",
+                       "/run/systemd/inaccessible/blk",
+                       "/run/systemd/inaccessible/fifo",
+                       "/run/systemd/inaccessible/sock")
                 if (access(p, F_OK) < 0)
                         return false;
-        }
 
         return true;
 }
index b23aadadcc654ea54c02b776609ad21c39d6e197..3e626dbe93cb15d8f0d230fcdc33cf060e4c086c 100644 (file)
@@ -998,7 +998,6 @@ TEST(read_full_file_offset_size) {
 }
 
 static void test_read_virtual_file_one(size_t max_size) {
-        const char *filename;
         int r;
 
         log_info("/* %s (max_size=%zu) */", __func__, max_size);
index ab26d5d096d234c25d079f780ab6273eca43699e..05da7a9e4854d529ebed8b191168583b1fe4d893 100644 (file)
 #include "util.h"
 
 TEST(gpt_types_against_architectures) {
-        const char *prefix;
         int r;
 
         /* Dumps a table indicating for which architectures we know we have matching GPT partition
          * types. Also validates whether we can properly categorize the entries. */
 
         FOREACH_STRING(prefix, "root-", "usr-")
-                for (int a = 0; a < _ARCHITECTURE_MAX; a++) {
-                        const char *suffix;
-
+                for (int a = 0; a < _ARCHITECTURE_MAX; a++)
                         FOREACH_STRING(suffix, "", "-verity", "-verity-sig") {
                                 _cleanup_free_ char *joined = NULL;
                                 sd_id128_t id;
@@ -48,7 +45,6 @@ TEST(gpt_types_against_architectures) {
 
                                 assert_se(gpt_partition_type_uuid_to_arch(id) == a);
                         }
-                }
 }
 
 DEFINE_TEST_MAIN(LOG_INFO);
index ebd520f7babfe976c142c78606f3e475cb839008..f88a9f9b249f2ed89e4aed0bd157375961f5797e 100644 (file)
@@ -39,7 +39,6 @@ static int test_hash_password(void) {
         /* As a warm-up exercise, check if we can hash passwords. */
 
         bool have_sane_hash = false;
-        const char *hash;
 
         FOREACH_STRING(hash,
                        "ew3bU1.hoKk4o",
@@ -68,7 +67,6 @@ static void test_hash_password_full(void) {
         log_info("/* %s */", __func__);
 
         _cleanup_free_ void *cd_data = NULL;
-        const char *i;
         int cd_size = 0;
 
         log_info("sizeof(struct crypt_data): %zu bytes", sizeof(struct crypt_data));
index 1642f82e40ddf1fe38a739eacf8e2a1d05a5121a..9c8c55bca29cea488ab5c6d5c0931ef42d65cb03 100644 (file)
@@ -114,7 +114,6 @@ int main(int argc, char *argv[]) {
         _cleanup_(dissected_image_unrefp) DissectedImage *dissected = NULL;
         _cleanup_(umount_and_rmdir_and_freep) char *mounted = NULL;
         pthread_t threads[N_THREADS];
-        const char *fs;
         sd_id128_t id;
         int r;
 
index 74d352268e1a902741d16c659263f3ff79c3b322..7e06fc419cdc62d0a4946a7b7b4a647c90d08ac2 100644 (file)
@@ -128,7 +128,6 @@ TEST(mount_flags_to_string) {
 TEST(bind_remount_recursive) {
         _cleanup_(rm_rf_physical_and_freep) char *tmp = NULL;
         _cleanup_free_ char *subdir = NULL;
-        const char *p;
 
         if (geteuid() != 0 || have_effective_cap(CAP_SYS_ADMIN) <= 0) {
                 (void) log_tests_skipped("not running privileged");
index 7f633ab2593b329b4fd2e096a3f0505b4528d51c..5f744b02886daaeec51a8a98b91dc61aa01560dc 100644 (file)
@@ -67,7 +67,6 @@ TEST(path_is_fs_type) {
 }
 
 TEST(path_is_temporary_fs) {
-        const char *s;
         int r;
 
         FOREACH_STRING(s, "/", "/run", "/sys", "/sys/", "/proc", "/i-dont-exist", "/var", "/var/lib") {
@@ -85,7 +84,6 @@ TEST(path_is_temporary_fs) {
 }
 
 TEST(path_is_read_only_fs) {
-        const char *s;
         int r;
 
         FOREACH_STRING(s, "/", "/run", "/sys", "/sys/", "/proc", "/i-dont-exist", "/var", "/var/lib") {
index edb782eb0d74a612a99d355525c2de1cd2006aa8..dabb0cd9737f55e3bdb542834dfdc38e694f1be4 100644 (file)
@@ -924,12 +924,10 @@ TEST(foreach_string) {
                 "waldo",
                 NULL
         };
-        const char *x;
-        unsigned i = 0;
 
+        unsigned i = 0;
         FOREACH_STRING(x, "foo", "bar", "waldo")
                 assert_se(streq_ptr(t[i++], x));
-
         assert_se(i == 3);
 
         FOREACH_STRING(x, "zzz")
index 7337b81227eb53be3094431e39db69bf131f59fb..f070c171fe4a5d0f2faca0df2c141e6f35bee8ad 100644 (file)
@@ -144,7 +144,6 @@ TEST(utf8_escape_non_printable) {
 }
 
 TEST(utf8_escape_non_printable_full) {
-        const char *s;
         FOREACH_STRING(s,
                        "goo goo goo",       /* ASCII */
                        "\001 \019\20\a",    /* control characters */
@@ -210,8 +209,6 @@ TEST(utf8_console_width) {
 }
 
 TEST(utf8_to_utf16) {
-        const char *p;
-
         FOREACH_STRING(p,
                        "abc",
                        "zażółcić gęślą jaźń",
index 8ba3fea9843ba24df0c4aa5f1d33d817f493f35c..c847266ed4a5ce0da6c6d9cd7cbec4da51d06d01 100644 (file)
@@ -39,7 +39,6 @@ static int populate_uid_cache(const char *root, Hashmap **ret) {
         /* The directory list is hardcoded here: /etc is the standard, and rpm-ostree uses /usr/lib. This
          * could be made configurable, but I don't see the point right now. */
 
-        const char *fname;
         FOREACH_STRING(fname, "/etc/passwd", "/usr/lib/passwd") {
                 _cleanup_fclose_ FILE *f = NULL;
 
@@ -78,7 +77,6 @@ static int populate_gid_cache(const char *root, Hashmap **ret) {
         if (!cache)
                 return -ENOMEM;
 
-        const char *fname;
         FOREACH_STRING(fname, "/etc/group", "/usr/lib/group") {
                 _cleanup_fclose_ FILE *f = NULL;