X Tutup
Skip to content

Commit 5980d46

Browse files
committed
strv: declare iterator of FOREACH_STRING() in the loop
Same idea as 0367788. 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.
1 parent 5b39139 commit 5980d46

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+66
-146
lines changed

src/activate/activate.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ static int open_sockets(int *epoll_fd, bool accept) {
123123

124124
static int exec_process(const char *name, char **argv, int start_fd, size_t n_fds) {
125125
_cleanup_strv_free_ char **envp = NULL;
126-
const char *var;
127126
int r;
128127

129128
if (arg_inetd && n_fds != 1)

src/basic/fs-util.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,6 @@ int get_files_in_directory(const char *path, char ***list) {
570570
}
571571

572572
static int getenv_tmp_dir(const char **ret_path) {
573-
const char *n;
574573
int r, ret = 0;
575574

576575
assert(ret_path);

src/basic/os-util.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ int open_extension_release(const char *root, const char *extension, char **ret_p
170170
}
171171
}
172172
} else {
173-
const char *p;
174-
175173
FOREACH_STRING(p, "/etc/os-release", "/usr/lib/os-release") {
176174
r = chase_symlinks(p, root, CHASE_PREFIX_ROOT,
177175
ret_path ? &q : NULL,

src/basic/strv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ void strv_print(char * const *l);
218218
})
219219

220220
#define _FOREACH_STRING(uniq, x, y, ...) \
221-
for (char **UNIQ_T(l, uniq) = STRV_MAKE(({ x = y; }), ##__VA_ARGS__); \
221+
for (const char *x, * const*UNIQ_T(l, uniq) = STRV_MAKE_CONST(({ x = y; }), ##__VA_ARGS__); \
222222
x; \
223223
x = *(++UNIQ_T(l, uniq)))
224224

src/basic/unit-file.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ bool lookup_paths_timestamp_hash_same(const LookupPaths *lp, uint64_t timestamp_
236236
}
237237

238238
static int directory_name_is_valid(const char *name) {
239-
const char *suffix;
240239

241240
/* Accept a directory whose name is a valid unit file name ending in .wants/, .requires/ or .d/ */
242241

src/boot/bootctl.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,12 +1255,11 @@ static int remove_variables(sd_id128_t uuid, const char *path, bool in_order) {
12551255
}
12561256

12571257
static int remove_loader_variables(void) {
1258-
const char *variable;
12591258
int r = 0;
12601259

12611260
/* Remove all persistent loader variables we define */
12621261

1263-
FOREACH_STRING(variable,
1262+
FOREACH_STRING(var,
12641263
EFI_LOADER_VARIABLE(LoaderConfigTimeout),
12651264
EFI_LOADER_VARIABLE(LoaderConfigTimeoutOneShot),
12661265
EFI_LOADER_VARIABLE(LoaderEntryDefault),
@@ -1269,15 +1268,15 @@ static int remove_loader_variables(void) {
12691268

12701269
int q;
12711270

1272-
q = efi_set_variable(variable, NULL, 0);
1271+
q = efi_set_variable(var, NULL, 0);
12731272
if (q == -ENOENT)
12741273
continue;
12751274
if (q < 0) {
1276-
log_warning_errno(q, "Failed to remove EFI variable %s: %m", variable);
1275+
log_warning_errno(q, "Failed to remove EFI variable %s: %m", var);
12771276
if (r >= 0)
12781277
r = q;
12791278
} else
1280-
log_info("Removed EFI variable %s.", variable);
1279+
log_info("Removed EFI variable %s.", var);
12811280
}
12821281

12831282
return r;

src/cgtop/cgtop.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,6 @@ static int refresh_one(
510510
}
511511

512512
static int refresh(const char *root, Hashmap *a, Hashmap *b, unsigned iteration) {
513-
const char *c;
514513
int r;
515514

516515
FOREACH_STRING(c, SYSTEMD_CGROUP_CONTROLLER, "cpu", "cpuacct", "memory", "io", "blkio", "pids") {

src/core/apparmor-setup.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ int mac_apparmor_setup(void) {
2424
#if HAVE_APPARMOR
2525
_cleanup_(aa_policy_cache_unrefp) aa_policy_cache *policy_cache = NULL;
2626
_cleanup_(aa_features_unrefp) aa_features *features = NULL;
27-
const char *current_file;
2827
_cleanup_free_ char *current_profile = NULL, *cache_dir_path = NULL;
2928
int r;
3029

src/core/cgroup.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,6 @@ void cgroup_oomd_xattr_apply(Unit *u, const char *cgroup_path) {
786786
}
787787

788788
static void cgroup_xattr_apply(Unit *u) {
789-
const char *xn;
790789
bool b;
791790

792791
assert(u);

src/core/efi-random.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,23 @@
2020
* is suitably validated. */
2121

2222
static void lock_down_efi_variables(void) {
23-
const char *p;
2423
int r;
2524

2625
/* Paranoia: let's restrict access modes of these a bit, so that unprivileged users can't use them to
2726
* identify the system or gain too much insight into what we might have credited to the entropy
2827
* pool. */
29-
FOREACH_STRING(p,
28+
FOREACH_STRING(path,
3029
EFIVAR_PATH(EFI_LOADER_VARIABLE(LoaderRandomSeed)),
3130
EFIVAR_PATH(EFI_LOADER_VARIABLE(LoaderSystemToken))) {
3231

33-
r = chattr_path(p, 0, FS_IMMUTABLE_FL, NULL);
32+
r = chattr_path(path, 0, FS_IMMUTABLE_FL, NULL);
3433
if (r == -ENOENT)
3534
continue;
3635
if (r < 0)
37-
log_warning_errno(r, "Failed to drop FS_IMMUTABLE_FL from %s, ignoring: %m", p);
36+
log_warning_errno(r, "Failed to drop FS_IMMUTABLE_FL from %s, ignoring: %m", path);
3837

39-
if (chmod(p, 0600) < 0)
40-
log_warning_errno(errno, "Failed to reduce access mode of %s, ignoring: %m", p);
38+
if (chmod(path, 0600) < 0)
39+
log_warning_errno(errno, "Failed to reduce access mode of %s, ignoring: %m", path);
4140
}
4241
}
4342

0 commit comments

Comments
 (0)
X Tutup