machinectl: reduce scope of iterator variables

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2020-01-11 12:33:24 +01:00
parent 957d9df388
commit 8571210a21

View file

@ -600,11 +600,9 @@ static void print_machine_status_info(sd_bus *bus, MachineStatusInfo *i) {
printf("\t Root: %s\n", i->root_directory);
if (i->n_netif > 0) {
size_t c;
fputs("\t Iface:", stdout);
for (c = 0; c < i->n_netif; c++) {
for (size_t c = 0; c < i->n_netif; c++) {
char name[IF_NAMESIZE+1];
if (format_ifname(i->netif[c], name)) {
@ -746,7 +744,7 @@ static int show_machine(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
bool properties, new_line = false;
sd_bus *bus = userdata;
int r = 0, i;
int r = 0;
assert(bus);
@ -763,7 +761,7 @@ static int show_machine(int argc, char *argv[], void *userdata) {
return r;
}
for (i = 1; i < argc; i++) {
for (int i = 1; i < argc; i++) {
const char *path = NULL;
r = sd_bus_call_method(bus,
@ -1084,7 +1082,7 @@ static int show_image(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
bool properties, new_line = false;
sd_bus *bus = userdata;
int r = 0, i;
int r = 0;
assert(bus);
@ -1105,7 +1103,7 @@ static int show_image(int argc, char *argv[], void *userdata) {
return r;
}
for (i = 1; i < argc; i++) {
for (int i = 1; i < argc; i++) {
const char *path = NULL;
r = sd_bus_call_method(
@ -1136,7 +1134,7 @@ static int show_image(int argc, char *argv[], void *userdata) {
static int kill_machine(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
sd_bus *bus = userdata;
int r, i;
int r;
assert(bus);
@ -1145,7 +1143,7 @@ static int kill_machine(int argc, char *argv[], void *userdata) {
if (!arg_kill_who)
arg_kill_who = "all";
for (i = 1; i < argc; i++) {
for (int i = 1; i < argc; i++) {
r = sd_bus_call_method(
bus,
"org.freedesktop.machine1",
@ -1179,13 +1177,13 @@ static int poweroff_machine(int argc, char *argv[], void *userdata) {
static int terminate_machine(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
sd_bus *bus = userdata;
int r, i;
int r;
assert(bus);
polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
for (i = 1; i < argc; i++) {
for (int i = 1; i < argc; i++) {
r = sd_bus_call_method(
bus,
"org.freedesktop.machine1",
@ -1550,13 +1548,13 @@ static int shell_machine(int argc, char *argv[], void *userdata) {
static int remove_image(int argc, char *argv[], void *userdata) {
sd_bus *bus = userdata;
int r, i;
int r;
assert(bus);
polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
for (i = 1; i < argc; i++) {
for (int i = 1; i < argc; i++) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
@ -1718,7 +1716,7 @@ static int start_machine(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(bus_wait_for_jobs_freep) BusWaitForJobs *w = NULL;
sd_bus *bus = userdata;
int r, i;
int r;
assert(bus);
@ -1729,7 +1727,7 @@ static int start_machine(int argc, char *argv[], void *userdata) {
if (r < 0)
return log_oom();
for (i = 1; i < argc; i++) {
for (int i = 1; i < argc; i++) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
_cleanup_free_ char *unit = NULL;
const char *object;
@ -1781,7 +1779,7 @@ static int enable_machine(int argc, char *argv[], void *userdata) {
size_t n_changes = 0;
const char *method = NULL;
sd_bus *bus = userdata;
int r, i;
int r;
assert(bus);
@ -1803,7 +1801,7 @@ static int enable_machine(int argc, char *argv[], void *userdata) {
if (r < 0)
return bus_log_create_error(r);
for (i = 1; i < argc; i++) {
for (int i = 1; i < argc; i++) {
_cleanup_free_ char *unit = NULL;
r = make_service_name(argv[i], &unit);
@ -2444,7 +2442,7 @@ static int list_transfers(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_free_ TransferInfo *transfers = NULL;
size_t n_transfers = 0, n_allocated = 0, j;
size_t n_transfers = 0, n_allocated = 0;
const char *type, *remote, *local;
sd_bus *bus = userdata;
uint32_t id, max_id = 0;
@ -2514,7 +2512,7 @@ static int list_transfers(int argc, char *argv[], void *userdata) {
(int) max_local, "LOCAL",
(int) max_remote, "REMOTE");
for (j = 0; j < n_transfers; j++)
for (size_t j = 0; j < n_transfers; j++)
if (transfers[j].progress < 0)
printf("%*" PRIu32 " %*s %-*s %-*s %-*s\n",
@ -2544,13 +2542,13 @@ static int list_transfers(int argc, char *argv[], void *userdata) {
static int cancel_transfer(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
sd_bus *bus = userdata;
int r, i;
int r;
assert(bus);
polkit_agent_open_if_enabled(arg_transport, arg_ask_password);
for (i = 1; i < argc; i++) {
for (int i = 1; i < argc; i++) {
uint32_t id;
r = safe_atou32(argv[i], &id);
@ -3040,7 +3038,6 @@ static int parse_argv(int argc, char *argv[]) {
done:
if (shell >= 0) {
char *t;
int i;
/* We found the "shell" verb while processing the argument list. Since we turned off reordering of the
* argument list initially let's readjust it now, and move the "shell" verb to the back. */
@ -3048,7 +3045,7 @@ done:
optind -= 1; /* place the option index where the "shell" verb will be placed */
t = argv[shell];
for (i = shell; i < optind; i++)
for (int i = shell; i < optind; i++)
argv[i] = argv[i+1];
argv[optind] = t;
}