Skip to content

Commit

Permalink
shared/install: reduce scope of iterator variables
Browse files Browse the repository at this point in the history
  • Loading branch information
keszybz committed Aug 22, 2020
1 parent eea63c0 commit de8be28
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/shared/install.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,10 @@ static bool unit_file_install_info_has_also(const UnitFileInstallInfo *i) {
}

void unit_file_presets_freep(UnitFilePresets *p) {
size_t i;

if (!p)
return;

for (i = 0; i < p->n_rules; i++) {
for (size_t i = 0; i < p->n_rules; i++) {
free(p->rules[i].pattern);
strv_free(p->rules[i].instances);
}
Expand Down Expand Up @@ -290,11 +288,9 @@ int unit_file_changes_add(
}

void unit_file_changes_free(UnitFileChange *changes, size_t n_changes) {
size_t i;

assert(changes || n_changes == 0);

for (i = 0; i < n_changes; i++) {
for (size_t i = 0; i < n_changes; i++) {
free(changes[i].path);
free(changes[i].source);
}
Expand All @@ -303,14 +299,13 @@ void unit_file_changes_free(UnitFileChange *changes, size_t n_changes) {
}

void unit_file_dump_changes(int r, const char *verb, const UnitFileChange *changes, size_t n_changes, bool quiet) {
size_t i;
bool logged = false;

assert(changes || n_changes == 0);
/* If verb is not specified, errors are not allowed! */
assert(verb || r >= 0);

for (i = 0; i < n_changes; i++) {
for (size_t i = 0; i < n_changes; i++) {
assert(verb || changes[i].type >= 0);

switch(changes[i].type) {
Expand Down Expand Up @@ -3091,12 +3086,11 @@ static int pattern_match_multiple_instances(

static int query_presets(const char *name, const UnitFilePresets *presets, char ***instance_name_list) {
PresetAction action = PRESET_UNKNOWN;
size_t i;
char **s;

if (!unit_name_is_valid(name, UNIT_NAME_ANY))
return -EINVAL;

for (i = 0; i < presets->n_rules; i++)
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;
Expand All @@ -3108,10 +3102,11 @@ static int query_presets(const char *name, const UnitFilePresets *presets, char
log_debug("Preset files don't specify rule for %s. Enabling.", name);
return 1;
case PRESET_ENABLE:
if (instance_name_list && *instance_name_list)
if (instance_name_list && *instance_name_list) {
char **s;
STRV_FOREACH(s, *instance_name_list)
log_debug("Preset files say enable %s.", *s);
else
} else
log_debug("Preset files say enable %s.", name);
return 1;
case PRESET_DISABLE:
Expand Down

0 comments on commit de8be28

Please sign in to comment.