UnitActiveState active_state;
sd_bus *bus;
char **name;
- int r, i;
+ int r;
bool found = false;
r = acquire_bus(BUS_MANAGER, &bus);
if (!arg_quiet)
puts(unit_active_state_to_string(active_state));
- for (i = 0; i < nb_states; ++i)
+ for (int i = 0; i < nb_states; ++i)
if (good_states[i] == active_state)
found = true;
}
static int show_installation_targets_client_side(const char *name) {
UnitFileChange *changes = NULL;
- size_t n_changes = 0, i;
+ size_t n_changes = 0;
UnitFileFlags flags;
char **p;
int r;
if (r < 0)
return log_error_errno(r, "Failed to get file links for %s: %m", name);
- for (i = 0; i < n_changes; i++)
+ for (size_t i = 0; i < n_changes; i++)
if (changes[i].type == UNIT_FILE_UNLINK)
printf(" %s\n", changes[i].path);
_cleanup_free_ char *n = NULL;
size_t max_len = MAX(columns(),20u);
size_t len = 0;
- int i;
if (!arg_plain) {
- for (i = level - 1; i >= 0; i--) {
+ for (int i = level - 1; i >= 0; i--) {
len += 2;
if (len > max_len - 3 && !arg_full) {
printf("%s...\n",max_len % 2 ? "" : " ");
static int output_jobs_list(sd_bus *bus, const struct job_info* jobs, unsigned n, bool skipped) {
_cleanup_(table_unrefp) Table *table = NULL;
- const struct job_info *j;
const char *on, *off;
int r;
(void) table_set_empty_string(table, "-");
- for (j = jobs; j < jobs + n; j++) {
+ for (const struct job_info *j = jobs; j < jobs + n; j++) {
if (streq(j->state, "running"))
on = ansi_highlight();
else
}
static void free_machines_list(struct machine_info *machine_infos, int n) {
- int i;
-
if (!machine_infos)
return;
- for (i = 0; i < n; i++)
+ for (int i = 0; i < n; i++)
machine_info_clear(&machine_infos[i]);
free(machine_infos);
static int output_machines_list(struct machine_info *machine_infos, unsigned n) {
_cleanup_(table_unrefp) Table *table = NULL;
- struct machine_info *m;
bool state_missing = false;
int r;
(void) table_set_empty_string(table, "-");
- for (m = machine_infos; m < machine_infos + n; m++) {
+ for (struct machine_info *m = machine_infos; m < machine_infos + n; m++) {
_cleanup_free_ char *mname = NULL;
const char *on_state = "", *on_failed = "";
bool circle = false;
int list_unit_files(int argc, char *argv[], void *userdata) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
_cleanup_free_ UnitFileList *units = NULL;
- UnitFileList *unit;
size_t size = 0;
unsigned c = 0;
const char *state;
return r;
if (install_client_side())
- for (unit = units; unit < units + c; unit++)
+ for (UnitFileList *unit = units; unit < units + c; unit++)
free(unit->path);
if (c == 0)
static int output_sockets_list(struct socket_info *socket_infos, unsigned cs) {
_cleanup_(table_unrefp) Table *table = NULL;
- struct socket_info *s;
const char *on, *off;
int r;
(void) table_set_empty_string(table, "-");
if (cs) {
- for (s = socket_infos; s < socket_infos + cs; s++) {
+ for (struct socket_info *s = socket_infos; s < socket_infos + cs; s++) {
_cleanup_free_ char *j = NULL;
const char *path;
_cleanup_strv_free_ char **sockets_with_suffix = NULL;
_cleanup_free_ UnitInfo *unit_infos = NULL;
_cleanup_free_ struct socket_info *socket_infos = NULL;
- const UnitInfo *u;
- struct socket_info *s;
unsigned cs = 0;
size_t size = 0;
int r, n;
if (n < 0)
return n;
- for (u = unit_infos; u < unit_infos + n; u++) {
+ for (const UnitInfo *u = unit_infos; u < unit_infos + n; u++) {
_cleanup_strv_free_ char **listening = NULL, **triggered = NULL;
- int i, c;
+ int c;
if (!endswith(u->id, ".socket"))
continue;
goto cleanup;
}
- for (i = 0; i < c; i++)
+ for (int i = 0; i < c; i++)
socket_infos[cs + i] = (struct socket_info) {
.machine = u->machine,
.id = u->id,
cleanup:
assert(cs == 0 || socket_infos);
- for (s = socket_infos; s < socket_infos + cs; s++) {
+ for (struct socket_info *s = socket_infos; s < socket_infos + cs; s++) {
free(s->type);
free(s->path);
if (s->own_triggered)
static int output_timers_list(struct timer_info *timer_infos, unsigned n) {
_cleanup_(table_unrefp) Table *table = NULL;
- struct timer_info *t;
const char *on, *off;
int r;
(void) table_set_empty_string(table, "-");
- if (n > 0) {
- for (t = timer_infos; t < timer_infos + n; t++) {
- _cleanup_free_ char *j = NULL, *activates = NULL;
- const char *unit;
-
- if (t->machine) {
- j = strjoin(t->machine, ":", t->id);
- if (!j)
- return log_oom();
- unit = j;
- } else
- unit = t->id;
+ for (struct timer_info *t = timer_infos; t < timer_infos + n; t++) {
+ _cleanup_free_ char *j = NULL, *activates = NULL;
+ const char *unit;
- activates = strv_join(t->triggered, ", ");
- if (!activates)
+ if (t->machine) {
+ j = strjoin(t->machine, ":", t->id);
+ if (!j)
return log_oom();
+ unit = j;
+ } else
+ unit = t->id;
- r = table_add_many(table,
- TABLE_TIMESTAMP, t->next_elapse,
- TABLE_TIMESTAMP_RELATIVE, t->next_elapse,
- TABLE_TIMESTAMP, t->last_trigger,
- TABLE_TIMESTAMP_RELATIVE, t->last_trigger,
- TABLE_STRING, unit,
- TABLE_STRING, activates);
- if (r < 0)
- return table_log_add_error(r);
- }
+ activates = strv_join(t->triggered, ", ");
+ if (!activates)
+ return log_oom();
+ r = table_add_many(table,
+ TABLE_TIMESTAMP, t->next_elapse,
+ TABLE_TIMESTAMP_RELATIVE, t->next_elapse,
+ TABLE_TIMESTAMP, t->last_trigger,
+ TABLE_TIMESTAMP_RELATIVE, t->last_trigger,
+ TABLE_STRING, unit,
+ TABLE_STRING, activates);
+ if (r < 0)
+ return table_log_add_error(r);
+ }
+
+ if (n > 0) {
on = ansi_highlight();
off = ansi_normal();
} else {
_cleanup_strv_free_ char **timers_with_suffix = NULL;
_cleanup_free_ struct timer_info *timer_infos = NULL;
_cleanup_free_ UnitInfo *unit_infos = NULL;
- struct timer_info *t;
- const UnitInfo *u;
size_t size = 0;
int n, c = 0;
dual_timestamp nw;
dual_timestamp_get(&nw);
- for (u = unit_infos; u < unit_infos + n; u++) {
+ for (const UnitInfo *u = unit_infos; u < unit_infos + n; u++) {
_cleanup_strv_free_ char **triggered = NULL;
dual_timestamp next = DUAL_TIMESTAMP_NULL;
usec_t m, last = 0;
output_timers_list(timer_infos, c);
cleanup:
- for (t = timer_infos; t < timer_infos + c; t++)
+ for (struct timer_info *t = timer_infos; t < timer_infos + c; t++)
strv_free(t->triggered);
return r;
} else if (endswith(name, "ExitStatus") && streq(contents, "aiai")) {
const int32_t *status, *signal;
- size_t n_status, n_signal, i;
+ size_t n_status, n_signal;
r = sd_bus_message_enter_container(m, 'r', "aiai");
if (r < 0)
fputc('=', stdout);
}
- for (i = 0; i < n_status; i++) {
+ for (size_t i = 0; i < n_status; i++) {
if (first)
first = false;
else
printf("%"PRIi32, status[i]);
}
- for (i = 0; i < n_signal; i++) {
+ for (size_t i = 0; i < n_signal; i++) {
const char *str;
str = signal_to_string((int) signal[i]);
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
_cleanup_free_ UnitInfo *unit_infos = NULL;
- const UnitInfo *u;
unsigned c;
int r, ret = 0;
typesafe_qsort(unit_infos, c, unit_info_compare);
- for (u = unit_infos; u < unit_infos + c; u++) {
+ for (const UnitInfo *u = unit_infos; u < unit_infos + c; u++) {
_cleanup_free_ char *p = NULL;
p = unit_dbus_path_from_name(u->id);
};
static const char *verb_to_method(const char *verb) {
- size_t i;
-
- for (i = 0; i < ELEMENTSOF(unit_actions); i++)
+ for (size_t i = 0; i < ELEMENTSOF(unit_actions); i++)
if (streq_ptr(unit_actions[i].verb, verb))
return unit_actions[i].method;
}
static const char *verb_to_job_type(const char *verb) {
- size_t i;
-
- for (i = 0; i < ELEMENTSOF(unit_actions); i++)
+ for (size_t i = 0; i < ELEMENTSOF(unit_actions); i++)
if (streq_ptr(unit_actions[i].verb, verb))
return unit_actions[i].job_type;
};
enum action verb_to_action(const char *verb) {
- enum action i;
-
- for (i = 0; i < _ACTION_MAX; i++)
+ for (enum action i = 0; i < _ACTION_MAX; i++)
if (streq_ptr(action_table[i].verb, verb))
return i;
}
void release_busses(void) {
- BusFocus w;
-
- for (w = 0; w < _BUS_FOCUS_MAX; w++)
+ for (BusFocus w = 0; w < _BUS_FOCUS_MAX; w++)
buses[w] = sd_bus_flush_close_unref(buses[w]);
}
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, i;
+ int r;
assert(bus);
assert(ret);
n = strv_length(mangled);
allocated = n + 1;
- for (i = 0; i < r; i++) {
+ for (int i = 0; i < r; i++) {
if (!GREEDY_REALLOC(mangled, allocated, n+2))
return log_oom();