summaryrefslogtreecommitdiffstats
path: root/src/shared/install.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-03-16 14:32:23 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-03-19 00:33:33 +0100
commitde010b0b2e50cf0b3837ce350b116bc92605f67a (patch)
tree226685fbb97461692562035501ebc21a314f718c /src/shared/install.c
parentlist: make LIST_FOREACH() and LIST_FOREACH_BACKWARDS() safer (diff)
downloadsystemd-de010b0b2e50cf0b3837ce350b116bc92605f67a.tar.xz
systemd-de010b0b2e50cf0b3837ce350b116bc92605f67a.zip
strv: make iterator in STRV_FOREACH() declaread in the loop
This also avoids multiple evaluations in STRV_FOREACH_BACKWARDS()
Diffstat (limited to 'src/shared/install.c')
-rw-r--r--src/shared/install.c28
1 files changed, 4 insertions, 24 deletions
diff --git a/src/shared/install.c b/src/shared/install.c
index 4a2698d6a1..53b5418804 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -864,7 +864,6 @@ static int find_symlinks_in_scope(
bool same_name_link_runtime = false, same_name_link_config = false;
bool enabled_in_runtime = false, enabled_at_all = false;
bool ignore_same_name = false;
- char **p;
int r;
assert(lp);
@@ -1421,7 +1420,6 @@ static int unit_file_search(
_cleanup_free_ char *template = NULL;
bool found_unit = false;
int r, result;
- char **p;
assert(info);
assert(lp);
@@ -1810,7 +1808,6 @@ static int install_info_symlink_alias(
UnitFileChange **changes,
size_t *n_changes) {
- char **s;
int r = 0, q;
assert(i);
@@ -1854,7 +1851,6 @@ static int install_info_symlink_wants(
_cleanup_free_ char *buf = NULL;
UnitNameFlags valid_dst_type = UNIT_NAME_ANY;
const char *n;
- char **s;
int r = 0, q;
assert(i);
@@ -2158,7 +2154,6 @@ int unit_file_mask(
_cleanup_(lookup_paths_free) LookupPaths lp = {};
const char *config_path;
- char **i;
int r;
assert(scope >= 0);
@@ -2207,7 +2202,6 @@ int unit_file_unmask(
_cleanup_strv_free_ char **todo = NULL;
const char *config_path;
size_t n_todo = 0;
- char **i;
int r, q;
assert(scope >= 0);
@@ -2299,7 +2293,6 @@ int unit_file_link(
_cleanup_strv_free_ char **todo = NULL;
const char *config_path;
size_t n_todo = 0;
- char **i;
int r, q;
assert(scope >= 0);
@@ -2399,7 +2392,6 @@ int unit_file_revert(
_cleanup_(lookup_paths_free) LookupPaths lp = {};
_cleanup_strv_free_ char **todo = NULL;
size_t n_todo = 0;
- char **i;
int r, q;
/* Puts a unit file back into vendor state. This means:
@@ -2419,7 +2411,6 @@ int unit_file_revert(
STRV_FOREACH(i, files) {
bool has_vendor = false;
- char **p;
if (!unit_name_is_valid(*i, UNIT_NAME_ANY))
return -EINVAL;
@@ -2503,7 +2494,6 @@ int unit_file_revert(
STRV_FOREACH(i, todo) {
_cleanup_strv_free_ char **fs = NULL;
const char *rp;
- char **j;
(void) get_files_in_directory(*i, &fs);
@@ -2556,7 +2546,6 @@ int unit_file_add_dependency(
_cleanup_(install_context_done) InstallContext c = {};
UnitFileInstallInfo *i, *target_info;
const char *config_path;
- char **f;
int r;
assert(scope >= 0);
@@ -2625,7 +2614,6 @@ int unit_file_enable(
_cleanup_(install_context_done) InstallContext c = {};
const char *config_path;
UnitFileInstallInfo *i;
- char **f;
int r;
assert(scope >= 0);
@@ -2668,7 +2656,6 @@ int unit_file_disable(
_cleanup_(install_context_done) InstallContext c = {};
_cleanup_set_free_free_ Set *remove_symlinks_to = NULL;
const char *config_path;
- char **i;
int r;
assert(scope >= 0);
@@ -2986,7 +2973,6 @@ static int presets_find_config(UnitFileScope scope, const char *root_dir, char *
static int read_presets(UnitFileScope scope, const char *root_dir, UnitFilePresets *presets) {
_cleanup_(unit_file_presets_freep) UnitFilePresets ps = {};
_cleanup_strv_free_ char **files = NULL;
- char **p;
int r;
assert(scope >= 0);
@@ -3104,7 +3090,6 @@ static int pattern_match_multiple_instances(
if (unit_name_is_valid(unit_name, UNIT_NAME_TEMPLATE)) {
_cleanup_strv_free_ char **out_strv = NULL;
- char **iter;
STRV_FOREACH(iter, rule.instances) {
_cleanup_free_ char *name = NULL;
@@ -3151,11 +3136,10 @@ 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) {
- char **s;
+ if (instance_name_list && *instance_name_list)
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:
@@ -3261,15 +3245,14 @@ static int preset_prepare_one(
return r;
if (r > 0) {
- if (instance_name_list) {
- char **s;
+ if (instance_name_list)
STRV_FOREACH(s, instance_name_list) {
r = install_info_discover_and_check(scope, plus, lp, *s, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS,
&i, changes, n_changes);
if (r < 0)
return r;
}
- } else {
+ else {
r = install_info_discover_and_check(scope, plus, lp, name, SEARCH_LOAD|SEARCH_FOLLOW_CONFIG_SYMLINKS,
&i, changes, n_changes);
if (r < 0)
@@ -3296,7 +3279,6 @@ int unit_file_preset(
_cleanup_(lookup_paths_free) LookupPaths lp = {};
_cleanup_(unit_file_presets_freep) UnitFilePresets presets = {};
const char *config_path;
- char **i;
int r;
assert(scope >= 0);
@@ -3336,7 +3318,6 @@ int unit_file_preset_all(
_cleanup_(lookup_paths_free) LookupPaths lp = {};
_cleanup_(unit_file_presets_freep) UnitFilePresets presets = {};
const char *config_path = NULL;
- char **i;
int r;
assert(scope >= 0);
@@ -3408,7 +3389,6 @@ int unit_file_get_list(
char **patterns) {
_cleanup_(lookup_paths_free) LookupPaths lp = {};
- char **dirname;
int r;
assert(scope >= 0);