strv: make iterator in STRV_FOREACH() declaread in the loop

This also avoids multiple evaluations in STRV_FOREACH_BACKWARDS()
This commit is contained in:
Yu Watanabe
2022-03-19 08:33:33 +09:00
parent 80a226b26b
commit de010b0b2e
210 changed files with 109 additions and 621 deletions
-1
View File
@@ -10,7 +10,6 @@
int verb_cancel(int argc, char *argv[], void *userdata) {
sd_bus *bus;
char **name;
int r;
if (argc <= 1) /* Shortcut to trivial_method() if no argument is given */
@@ -11,7 +11,6 @@ int verb_clean_or_freeze(int argc, char *argv[], void *userdata) {
_cleanup_(bus_wait_for_units_freep) BusWaitForUnits *w = NULL;
_cleanup_strv_free_ char **names = NULL;
int r, ret = EXIT_SUCCESS;
char **name;
const char *method;
sd_bus *bus;
+1 -5
View File
@@ -26,7 +26,6 @@ int verb_cat(int argc, char *argv[], void *userdata) {
_cleanup_(hashmap_freep) Hashmap *cached_name_map = NULL, *cached_id_map = NULL;
_cleanup_(lookup_paths_free) LookupPaths lp = {};
_cleanup_strv_free_ char **names = NULL;
char **name;
sd_bus *bus;
bool first = true;
int r, rc = 0;
@@ -145,7 +144,6 @@ static int create_edit_temp_file(const char *new_path, const char *original_path
} else if (original_unit_paths) {
_cleanup_free_ char *new_contents = NULL;
_cleanup_fclose_ FILE *f = NULL;
char **path;
r = mac_selinux_create_file_prepare(new_path, S_IFREG);
if (r < 0)
@@ -318,7 +316,7 @@ static int run_editor(char **paths) {
if (r < 0)
return r;
if (r == 0) {
char **editor_args = NULL, **tmp_path, **original_path;
char **editor_args = NULL;
size_t n_editor_args = 0, i = 1, argc;
const char **args, *editor, *p;
@@ -379,7 +377,6 @@ static int run_editor(char **paths) {
static int find_paths_to_edit(sd_bus *bus, char **names, char ***paths) {
_cleanup_(hashmap_freep) Hashmap *cached_name_map = NULL, *cached_id_map = NULL;
_cleanup_(lookup_paths_free) LookupPaths lp = {};
char **name;
int r;
assert(names);
@@ -501,7 +498,6 @@ int verb_edit(int argc, char *argv[], void *userdata) {
_cleanup_(lookup_paths_free) LookupPaths lp = {};
_cleanup_strv_free_ char **names = NULL;
_cleanup_strv_free_ char **paths = NULL;
char **original, **tmp;
sd_bus *bus;
int r;
-3
View File
@@ -12,7 +12,6 @@
#include "systemctl.h"
static int normalize_filenames(char **names) {
char **u;
int r;
STRV_FOREACH(u, names)
@@ -40,7 +39,6 @@ static int normalize_filenames(char **names) {
}
static int normalize_names(char **names) {
char **u;
bool was_path = false;
STRV_FOREACH(u, names) {
@@ -141,7 +139,6 @@ int verb_enable(int argc, char *argv[], void *userdata) {
sd_bus *bus;
if (STR_IN_SET(verb, "mask", "unmask")) {
char **name;
_cleanup_(lookup_paths_free) LookupPaths lp = {};
r = lookup_paths_init(&lp, arg_scope, 0, arg_root);
-1
View File
@@ -13,7 +13,6 @@ static int check_unit_generic(int code, const UnitActiveState good_states[], int
_cleanup_strv_free_ char **names = NULL;
UnitActiveState active_state;
sd_bus *bus;
char **name;
int r;
bool found = false;
-1
View File
@@ -59,7 +59,6 @@ static int show_installation_targets(sd_bus *bus, const char *name) {
int verb_is_enabled(int argc, char *argv[], void *userdata) {
_cleanup_strv_free_ char **names = NULL;
bool enabled;
char **name;
int r;
r = mangle_names("to check", strv_skip(argv, 1), &names);
+1 -1
View File
@@ -8,7 +8,7 @@
int verb_kill(int argc, char *argv[], void *userdata) {
_cleanup_strv_free_ char **names = NULL;
char *kill_who = NULL, **name;
char *kill_who = NULL;
sd_bus *bus;
int r, q;
+1 -2
View File
@@ -63,7 +63,6 @@ static int list_dependencies_one(
unsigned branches) {
_cleanup_strv_free_ char **deps = NULL;
char **c;
int r;
assert(bus);
@@ -138,7 +137,7 @@ static int list_dependencies_one(
int verb_list_dependencies(int argc, char *argv[], void *userdata) {
_cleanup_strv_free_ char **units = NULL, **done = NULL;
char **u, **patterns;
char **patterns;
sd_bus *bus;
int r;
-1
View File
@@ -93,7 +93,6 @@ static int get_machine_list(
struct machine_info *machine_infos = NULL;
_cleanup_strv_free_ char **m = NULL;
_cleanup_free_ char *hn = NULL;
char **i;
int c = 0, r;
hn = gethostname_malloc();
-1
View File
@@ -49,7 +49,6 @@ static int get_unit_list_recursive(
if (arg_recursive) {
_cleanup_strv_free_ char **machines = NULL;
char **i;
r = sd_get_machine_names(&machines);
if (r < 0)
-2
View File
@@ -112,7 +112,6 @@ int logind_check_inhibitors(enum action a) {
uint32_t uid, pid;
sd_bus *bus;
unsigned c = 0;
char **s;
int r;
if (arg_check_inhibitors == 0 || arg_force > 0)
@@ -399,7 +398,6 @@ int help_boot_loader_entry(void) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_strv_free_ char **l = NULL;
sd_bus *bus;
char **i;
int r;
r = acquire_bus(BUS_FULL, &bus);
-1
View File
@@ -10,7 +10,6 @@
int verb_reset_failed(int argc, char *argv[], void *userdata) {
_cleanup_strv_free_ char **names = NULL;
sd_bus *bus;
char **name;
int r, q;
if (argc <= 1) /* Shortcut to trivial_method() if no argument is given */
@@ -171,7 +171,6 @@ int verb_import_environment(int argc, char *argv[], void *userdata) {
strv_env_clean_with_callback(copy, invalid_callback, NULL);
char **e;
STRV_FOREACH(e, copy)
if (string_has_cc(*e, NULL))
log_notice("Environment variable $%.*s contains control characters, importing anyway.",
@@ -180,8 +179,6 @@ int verb_import_environment(int argc, char *argv[], void *userdata) {
r = sd_bus_message_append_strv(m, copy);
} else {
char **a, **b;
r = sd_bus_message_open_container(m, 'a', "s");
if (r < 0)
return bus_log_create_error(r);
-1
View File
@@ -46,7 +46,6 @@ static int set_property_one(sd_bus *bus, const char *name, char **properties) {
int verb_set_property(int argc, char *argv[], void *userdata) {
sd_bus *bus;
_cleanup_strv_free_ char **names = NULL;
char **name;
int r, k;
r = acquire_bus(BUS_MANAGER, &bus);
-7
View File
@@ -307,7 +307,6 @@ static void print_status_info(
_cleanup_free_ char *formatted_path = NULL;
usec_t timestamp;
const char *path;
char **t, **t2;
int r;
assert(i);
@@ -366,7 +365,6 @@ static void print_status_info(
if (!strv_isempty(i->dropin_paths)) {
_cleanup_free_ char *dir = NULL;
bool last = false;
char ** dropin;
STRV_FOREACH(dropin, i->dropin_paths) {
_cleanup_free_ char *dropin_formatted = NULL;
@@ -772,8 +770,6 @@ static void print_status_info(
}
static void show_unit_help(UnitStatusInfo *i) {
char **p;
assert(i);
if (!i->documentation) {
@@ -1076,7 +1072,6 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
if (FLAGS_SET(flags, BUS_PRINT_PROPERTY_SHOW_EMPTY) || allow_list || !strv_isempty(l)) {
bool first = true;
char **i;
if (!FLAGS_SET(flags, BUS_PRINT_PROPERTY_ONLY_VALUE)) {
fputs(name, stdout);
@@ -1968,7 +1963,6 @@ static int show_one(
.io_read_bytes = UINT64_MAX,
.io_write_bytes = UINT64_MAX,
};
char **pp;
int r;
assert(path);
@@ -2192,7 +2186,6 @@ int verb_show(int argc, char *argv[], void *userdata) {
ret = show_all(bus, &new_line, &ellipsized);
} else {
_cleanup_free_ char **patterns = NULL;
char **name;
STRV_FOREACH(name, strv_skip(argv, 1)) {
_cleanup_free_ char *path = NULL, *unit = NULL;
+1 -5
View File
@@ -199,16 +199,13 @@ static int enqueue_marked_jobs(
if (r < 0)
return bus_log_parse_error(r);
if (w) {
char **path;
if (w)
STRV_FOREACH(path, paths) {
log_debug("Adding %s to the set", *path);
r = bus_wait_for_jobs_add(w, *path);
if (r < 0)
return log_error_errno(r, "Failed to watch job %s: %m", *path);
}
}
return 0;
}
@@ -269,7 +266,6 @@ int verb_start(int argc, char *argv[], void *userdata) {
_cleanup_strv_free_ char **names = NULL;
int r, ret = EXIT_SUCCESS;
sd_bus *bus;
char **name;
if (arg_wait && !STR_IN_SET(argv[0], "start", "restart"))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+1 -6
View File
@@ -234,7 +234,6 @@ int get_unit_list(
int expand_unit_names(sd_bus *bus, char **names, const char* suffix, char ***ret, bool *ret_expanded) {
_cleanup_strv_free_ char **mangled = NULL, **globs = NULL;
char **name;
int r;
assert(bus);
@@ -294,7 +293,6 @@ int check_triggering_units(sd_bus *bus, const char *unit) {
_cleanup_strv_free_ char **triggered_by = NULL;
bool print_warning_label = true;
UnitActiveState active_state;
char **i;
int r;
r = unit_name_mangle(unit, 0, &n);
@@ -386,8 +384,6 @@ void warn_unit_file_changed(const char *unit) {
}
int unit_file_find_path(LookupPaths *lp, const char *unit_name, char **ret_unit_path) {
char **p;
assert(lp);
assert(unit_name);
@@ -666,7 +662,6 @@ int unit_exists(LookupPaths *lp, const char *unit) {
int append_unit_dependencies(sd_bus *bus, char **names, char ***ret) {
_cleanup_strv_free_ char **with_deps = NULL;
char **name;
assert(bus);
assert(ret);
@@ -860,7 +855,7 @@ UnitFileFlags unit_file_flags_from_args(void) {
int mangle_names(const char *operation, char **original_names, char ***ret_mangled_names) {
_cleanup_strv_free_ char **l = NULL;
char **i, **name;
char **i;
int r;
assert(ret_mangled_names);