/* The type of the iterator 'i' is automatically determined by the type of 'head', and declared in the
* loop. Hence, do not declare the same variable in the outer scope. Sometimes, we set 'head' through
* hashmap_get(). In that case, you need to explicitly cast the result. */
+#define LIST_FOREACH_WITH_NEXT(name,i,n,head) \
+ for (typeof(*(head)) *n, *i = (head); i && (n = i->name##_next, true); i = n)
+
#define LIST_FOREACH(name,i,head) \
- for (typeof(*(head)) *i = (head); i; i = i->name##_next)
+ LIST_FOREACH_WITH_NEXT(name, i, UNIQ_T(n, UNIQ), head)
-#define LIST_FOREACH_SAFE(name,i,n,head) \
- for (typeof(*(head)) *n, *i = (head); i && ((n = i->name##_next), 1); i = n)
+#define _LIST_FOREACH_WITH_PREV(name,i,p,start) \
+ for (typeof(*(start)) *p, *i = (start); i && (p = i->name##_prev, true); i = p)
-#define LIST_FOREACH_BACKWARDS(name,i,p) \
- for (typeof(*(p)) *i = (p); i; i = i->name##_prev)
+#define LIST_FOREACH_BACKWARDS(name,i,start) \
+ _LIST_FOREACH_WITH_PREV(name, i, UNIQ_T(p, UNIQ), start)
/* Iterate through all the members of the list p is included in, but skip over p */
#define LIST_FOREACH_OTHERS(name,i,p) \
return;
l = hashmap_get(m->devices_by_sysfs, sysfs);
- LIST_FOREACH_SAFE(same_sysfs, d, n, l)
+ LIST_FOREACH(same_sysfs, d, l)
device_update_found_one(d, found, mask);
}
assert(sysfs);
l = hashmap_get(m->devices_by_sysfs, sysfs);
- LIST_FOREACH_SAFE(same_sysfs, d, n, l) {
+ LIST_FOREACH(same_sysfs, d, l) {
if (d->state == DEVICE_DEAD)
continue;
assert(s);
assert(name);
- LIST_FOREACH_SAFE(fd_store, fs, n, s->fd_store) {
+ LIST_FOREACH(fd_store, fs, s->fd_store) {
if (!streq(fs->fdname, name))
continue;
void dhcp6_ia_clear_addresses(DHCP6IA *ia) {
assert(ia);
- LIST_FOREACH_SAFE(addresses, a, n, ia->addresses)
+ LIST_FOREACH(addresses, a, ia->addresses)
free(a);
ia->addresses = NULL;
list->uptodate = false;
hashmap_clear_with_destructor(list->unique_entries, udev_list_entry_free);
} else
- LIST_FOREACH_SAFE(entries, i, n, list->entries)
+ LIST_FOREACH(entries, i, list->entries)
udev_list_entry_free(i);
}
"%s: Missing PrivateKey= or PrivateKeyFile=, "
"Ignoring network device.", filename);
- LIST_FOREACH_SAFE(peers, peer, peer_next, w->peers) {
+ LIST_FOREACH(peers, peer, w->peers) {
if (wireguard_peer_verify(peer) < 0) {
wireguard_peer_free(peer);
continue;
static void context_unload_partition_table(Context *context) {
assert(context);
- LIST_FOREACH_SAFE(partitions, p, next, context->partitions) {
+ LIST_FOREACH(partitions, p, context->partitions) {
/* Entirely remove partitions that have no configuration */
if (PARTITION_IS_FOREIGN(p)) {
if (!first)
return false;
- LIST_FOREACH_SAFE(by_key, i, n, first) {
+ LIST_FOREACH(by_key, i, first) {
prioq_remove(c->by_expiry, i, &i->prioq_idx);
dns_cache_item_free(i);
}
}
if (error != 0)
- LIST_FOREACH_SAFE(transactions_by_stream, t, n, s->transactions)
+ LIST_FOREACH(transactions_by_stream, t, s->transactions)
on_transaction_stream_error(t, error);
return 0;
static void save_state_queue_remove(Context *c, int idx, const char *state_file) {
assert(c);
- LIST_FOREACH_SAFE(queue, item, tmp, c->write_queue)
+ LIST_FOREACH(queue, item, c->write_queue)
if ((state_file && streq(item->file, state_file)) || idx == item->rfkill_idx) {
log_debug("Canceled previous save state of '%s' to %s.", one_zero(item->state), item->file);
LIST_REMOVE(queue, c->write_queue, item);
}
Condition* condition_free_list_type(Condition *head, ConditionType type) {
- LIST_FOREACH_SAFE(conditions, c, n, head)
+ LIST_FOREACH(conditions, c, head)
if (type < 0 || c->type == type) {
LIST_REMOVE(conditions, head, c);
condition_free(c);
assert(head);
assert(changed);
- LIST_FOREACH_SAFE(mount_point, m, n, *head) {
+ LIST_FOREACH(mount_point, m, *head) {
log_info("Deactivating swap %s.", m->path);
if (swapoff(m->path) < 0) {
log_warning_errno(errno, "Could not deactivate swap %s: %m", m->path);
(void) get_block_device("/", &rootdev);
- LIST_FOREACH_SAFE(mount_point, m, n, *head) {
+ LIST_FOREACH(mount_point, m, *head) {
if (major(rootdev) != 0 && rootdev == m->devnum) {
n_failed++;
continue;
(void) get_block_device("/", &rootdev);
- LIST_FOREACH_SAFE(mount_point, m, n, *head) {
+ LIST_FOREACH(mount_point, m, *head) {
if (major(rootdev) != 0 && rootdev == m->devnum) {
n_failed ++;
continue;
(void) get_block_device("/", &rootdev);
- LIST_FOREACH_SAFE(mount_point, m, n, *head) {
+ LIST_FOREACH(mount_point, m, *head) {
if (major(rootdev) != 0 && rootdev == m->devnum) {
n_failed ++;
continue;
}
}
- LIST_FOREACH_SAFE(names, n, nx, m->link_servers)
+ LIST_FOREACH(names, n, m->link_servers)
if (n->marked) {
server_name_free(n);
changed = true;
if (!ctx)
return;
- LIST_FOREACH_SAFE(configs, config, config_next, ctx->configs)
+ LIST_FOREACH(configs, config, ctx->configs)
link_config_free(config);
}
static void udev_rule_line_clear_tokens(UdevRuleLine *rule_line) {
assert(rule_line);
- LIST_FOREACH_SAFE(tokens, i, next, rule_line->tokens)
+ LIST_FOREACH(tokens, i, rule_line->tokens)
udev_rule_token_free(i);
rule_line->tokens = NULL;
if (!rule_file)
return;
- LIST_FOREACH_SAFE(rule_lines, i, next, rule_file->rule_lines)
+ LIST_FOREACH(rule_lines, i, rule_file->rule_lines)
udev_rule_line_free(i);
free(rule_file->filename);
if (!rules)
return NULL;
- LIST_FOREACH_SAFE(rule_files, i, next, rules->rule_files)
+ LIST_FOREACH(rule_files, i, rules->rule_files)
udev_rule_file_free(i);
hashmap_free_free_key(rules->known_users);
assert(rule_file);
/* link GOTOs to LABEL rules in this file to be able to fast-forward */
- LIST_FOREACH_SAFE(rule_lines, line, line_next, rule_file->rule_lines) {
+ LIST_FOREACH(rule_lines, line, rule_file->rule_lines) {
if (!FLAGS_SET(line->type, LINE_HAS_GOTO))
continue;
DEVICE_TRACE_POINT(rules_apply_line, event->dev, line->rule_file->filename, line->line_number);
- LIST_FOREACH_SAFE(tokens, token, next_token, line->tokens) {
+ LIST_FOREACH(tokens, token, line->tokens) {
line->current_token = token;
if (token_is_for_parents(token)) {
LIST_FOREACH(rule_files, file, rules->rule_files) {
rules->current_file = file;
- LIST_FOREACH_SAFE(rule_lines, line, next_line, file->rule_lines) {
+ LIST_FOREACH_WITH_NEXT(rule_lines, line, next_line, file->rule_lines) {
file->current_line = line;
r = udev_rule_apply_line_to_event(rules, event, timeout_usec, timeout_signal, properties_list, &next_line);
if (r < 0)
}
static void event_queue_cleanup(Manager *manager, EventState match_state) {
- LIST_FOREACH_SAFE(event, event, tmp, manager->events) {
+ LIST_FOREACH(event, event, manager->events) {
if (match_state != EVENT_UNDEF && match_state != event->state)
continue;
return log_warning_errno(r, "Failed to read udev rules: %m");
}
- LIST_FOREACH_SAFE(event, event, event_next, manager->events) {
+ LIST_FOREACH(event, event, manager->events) {
if (event->state != EVENT_QUEUED)
continue;