diff --git a/coccinelle/macros.h b/coccinelle/macros.h index 6a0a64bb05c..f44b3f2d26f 100644 --- a/coccinelle/macros.h +++ b/coccinelle/macros.h @@ -189,8 +189,6 @@ (i) != (p); \ (i) = (i)->name##_next ? (i)->name##_next : (head)) -#define LIST_IS_EMPTY(head) \ - (!(head)) #define LIST_JOIN(name,a,b) \ do { \ assert(b); \ diff --git a/src/basic/list.h b/src/basic/list.h index 58e83a6cb2b..ca300396908 100644 --- a/src/basic/list.h +++ b/src/basic/list.h @@ -170,9 +170,6 @@ i != (p); \ i = i->name##_next ? i->name##_next : (head)) -#define LIST_IS_EMPTY(head) \ - (!(head)) - /* Join two lists tail to head: a->b, c->d to a->b->c->d and de-initialise second list */ #define LIST_JOIN(name,a,b) \ do { \ diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 25707fce642..0fce812b400 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -1689,7 +1689,7 @@ static bool unit_get_needs_bpf_foreign_program(Unit *u) { if (!c) return false; - return !LIST_IS_EMPTY(c->bpf_foreign_programs); + return !!c->bpf_foreign_programs; } static bool unit_get_needs_socket_bind(Unit *u) { diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c index 607370d7bfe..7e95f0e3907 100644 --- a/src/core/dbus-cgroup.c +++ b/src/core/dbus-cgroup.c @@ -737,7 +737,7 @@ static int bus_cgroup_set_transient_property( unit_write_setting(u, flags, name, buf); - if (!LIST_IS_EMPTY(c->bpf_foreign_programs)) { + if (c->bpf_foreign_programs) { r = bpf_foreign_supported(); if (r < 0) return r; diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c index 1a9e5da6350..8de092ee4e2 100644 --- a/src/core/dbus-execute.c +++ b/src/core/dbus-execute.c @@ -1698,16 +1698,16 @@ int bus_exec_context_set_transient_property( return r; if (!UNIT_WRITE_FLAGS_NOOP(flags)) { - if (LIST_IS_EMPTY(options)) { - c->root_image_options = mount_options_free_all(c->root_image_options); - unit_write_settingf(u, flags, name, "%s=", name); - } else { + if (options) { LIST_JOIN(mount_options, c->root_image_options, options); unit_write_settingf( u, flags|UNIT_ESCAPE_SPECIFIERS, name, "%s=%s", name, format_str); + } else { + c->root_image_options = mount_options_free_all(c->root_image_options); + unit_write_settingf(u, flags, name, "%s=", name); } } diff --git a/src/core/dbus-util.c b/src/core/dbus-util.c index 32a2ec0ff90..264a4f55b67 100644 --- a/src/core/dbus-util.c +++ b/src/core/dbus-util.c @@ -216,7 +216,7 @@ int bus_read_mount_options( if (r < 0) return r; - if (!LIST_IS_EMPTY(options)) { + if (options) { if (ret_format_str) { char *final = strjoin(*ret_format_str, !isempty(*ret_format_str) ? separator : "", format_str); if (!final) diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 3ff6eae8fce..313f667cd79 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -1691,11 +1691,11 @@ int config_parse_root_image_options( LIST_APPEND(mount_options, options, TAKE_PTR(o)); } - /* empty spaces/separators only */ - if (LIST_IS_EMPTY(options)) - c->root_image_options = mount_options_free_all(c->root_image_options); - else + if (options) LIST_JOIN(mount_options, c->root_image_options, options); + else + /* empty spaces/separators only */ + c->root_image_options = mount_options_free_all(c->root_image_options); return 0; } diff --git a/src/core/unit.c b/src/core/unit.c index 180dccc2b29..40fc79995ad 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -4138,7 +4138,7 @@ int unit_patch_contexts(Unit *u) { cc->device_policy == CGROUP_DEVICE_POLICY_AUTO) cc->device_policy = CGROUP_DEVICE_POLICY_CLOSED; - if ((ec->root_image || !LIST_IS_EMPTY(ec->mount_images)) && + if ((ec->root_image || ec->mount_images) && (cc->device_policy != CGROUP_DEVICE_POLICY_AUTO || cc->device_allow)) { /* When RootImage= or MountImages= is specified, the following devices are touched. */ diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c index cea1c009d61..df48b3ce046 100644 --- a/src/libsystemd/sd-event/sd-event.c +++ b/src/libsystemd/sd-event/sd-event.c @@ -49,19 +49,19 @@ static bool event_source_is_offline(sd_event_source *s) { } static const char* const event_source_type_table[_SOURCE_EVENT_SOURCE_TYPE_MAX] = { - [SOURCE_IO] = "io", - [SOURCE_TIME_REALTIME] = "realtime", - [SOURCE_TIME_BOOTTIME] = "bootime", - [SOURCE_TIME_MONOTONIC] = "monotonic", + [SOURCE_IO] = "io", + [SOURCE_TIME_REALTIME] = "realtime", + [SOURCE_TIME_BOOTTIME] = "bootime", + [SOURCE_TIME_MONOTONIC] = "monotonic", [SOURCE_TIME_REALTIME_ALARM] = "realtime-alarm", [SOURCE_TIME_BOOTTIME_ALARM] = "boottime-alarm", - [SOURCE_SIGNAL] = "signal", - [SOURCE_CHILD] = "child", - [SOURCE_DEFER] = "defer", - [SOURCE_POST] = "post", - [SOURCE_EXIT] = "exit", - [SOURCE_WATCHDOG] = "watchdog", - [SOURCE_INOTIFY] = "inotify", + [SOURCE_SIGNAL] = "signal", + [SOURCE_CHILD] = "child", + [SOURCE_DEFER] = "defer", + [SOURCE_POST] = "post", + [SOURCE_EXIT] = "exit", + [SOURCE_WATCHDOG] = "watchdog", + [SOURCE_INOTIFY] = "inotify", }; DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(event_source_type, int); @@ -124,10 +124,10 @@ struct sd_event { Hashmap *inotify_data; /* indexed by priority */ /* A list of inode structures that still have an fd open, that we need to close before the next loop iteration */ - LIST_HEAD(struct inode_data, inode_data_to_close); + LIST_HEAD(struct inode_data, inode_data_to_close_list); /* A list of inotify objects that already have events buffered which aren't processed yet */ - LIST_HEAD(struct inotify_data, inotify_data_buffered); + LIST_HEAD(struct inotify_data, buffered_inotify_data_list); pid_t original_pid; @@ -1692,7 +1692,7 @@ static void event_free_inotify_data(sd_event *e, struct inotify_data *d) { assert(hashmap_isempty(d->wd)); if (d->buffer_filled > 0) - LIST_REMOVE(buffered, e->inotify_data_buffered, d); + LIST_REMOVE(buffered, e->buffered_inotify_data_list, d); hashmap_free(d->inodes); hashmap_free(d->wd); @@ -1801,10 +1801,10 @@ static void event_free_inode_data( if (!d) return; - assert(LIST_IS_EMPTY(d->event_sources)); + assert(!d->event_sources); if (d->fd >= 0) { - LIST_REMOVE(to_close, e->inode_data_to_close, d); + LIST_REMOVE(to_close, e->inode_data_to_close_list, d); safe_close(d->fd); } @@ -1864,7 +1864,7 @@ static void event_gc_inode_data( if (!d) return; - if (!LIST_IS_EMPTY(d->event_sources)) + if (d->event_sources) return; inotify_data = d->inotify_data; @@ -2066,7 +2066,7 @@ static int event_add_inotify_fd_internal( } } - LIST_PREPEND(to_close, e->inode_data_to_close, inode_data); + LIST_PREPEND(to_close, e->inode_data_to_close_list, inode_data); } /* Link our event source to the inode data object */ @@ -2353,7 +2353,7 @@ _public_ int sd_event_source_set_priority(sd_event_source *s, int64_t priority) goto fail; } - LIST_PREPEND(to_close, s->event->inode_data_to_close, new_inode_data); + LIST_PREPEND(to_close, s->event->inode_data_to_close_list, new_inode_data); } /* Move the event source to the new inode data structure */ @@ -3419,7 +3419,7 @@ static int event_inotify_data_read(sd_event *e, struct inotify_data *d, uint32_t assert(n > 0); d->buffer_filled = (size_t) n; - LIST_PREPEND(buffered, e->inotify_data_buffered, d); + LIST_PREPEND(buffered, e->buffered_inotify_data_list, d); return 1; } @@ -3437,7 +3437,7 @@ static void event_inotify_data_drop(sd_event *e, struct inotify_data *d, size_t d->buffer_filled -= sz; if (d->buffer_filled == 0) - LIST_REMOVE(buffered, e->inotify_data_buffered, d); + LIST_REMOVE(buffered, e->buffered_inotify_data_list, d); } static int event_inotify_data_process(sd_event *e, struct inotify_data *d) { @@ -3530,7 +3530,7 @@ static int process_inotify(sd_event *e) { assert(e); - LIST_FOREACH(buffered, d, e->inotify_data_buffered) { + LIST_FOREACH(buffered, d, e->buffered_inotify_data_list) { r = event_inotify_data_process(e, d); if (r < 0) return r; @@ -3827,11 +3827,11 @@ static void event_close_inode_data_fds(sd_event *e) { * for the inode). Hence, let's close them when entering the first iteration after they were added, as a * compromise. */ - while ((d = e->inode_data_to_close)) { + while ((d = e->inode_data_to_close_list)) { assert(d->fd >= 0); d->fd = safe_close(d->fd); - LIST_REMOVE(to_close, e->inode_data_to_close, d); + LIST_REMOVE(to_close, e->inode_data_to_close_list, d); } } @@ -3885,7 +3885,7 @@ _public_ int sd_event_prepare(sd_event *e) { event_close_inode_data_fds(e); - if (event_next_pending(e) || e->need_process_child || !LIST_IS_EMPTY(e->inotify_data_buffered)) + if (event_next_pending(e) || e->need_process_child || e->buffered_inotify_data_list) goto pending; e->state = SD_EVENT_ARMED; @@ -3965,7 +3965,7 @@ static int process_epoll(sd_event *e, usec_t timeout, int64_t threshold, int64_t n_event_max = MALLOC_ELEMENTSOF(e->event_queue); /* If we still have inotify data buffered, then query the other fds, but don't wait on it */ - if (!LIST_IS_EMPTY(e->inotify_data_buffered)) + if (e->buffered_inotify_data_list) timeout = 0; for (;;) { diff --git a/src/resolve/resolved-bus.c b/src/resolve/resolved-bus.c index e19d3de8ea7..9e7d1cc380c 100644 --- a/src/resolve/resolved-bus.c +++ b/src/resolve/resolved-bus.c @@ -1988,7 +1988,7 @@ static int bus_method_register_service(sd_bus_message *message, void *userdata, if (r < 0) return r; - LIST_INSERT_AFTER(items, txt_data->txt, last, i); + LIST_INSERT_AFTER(items, txt_data->txts, last, i); last = i; r = sd_bus_message_exit_container(message); @@ -2003,7 +2003,7 @@ static int bus_method_register_service(sd_bus_message *message, void *userdata, if (r < 0) return r; - if (txt_data->txt) { + if (txt_data->txts) { LIST_PREPEND(items, service->txt_data_items, txt_data); txt_data = NULL; } @@ -2022,7 +2022,7 @@ static int bus_method_register_service(sd_bus_message *message, void *userdata, if (!txt_data) return log_oom(); - r = dns_txt_item_new_empty(&txt_data->txt); + r = dns_txt_item_new_empty(&txt_data->txts); if (r < 0) return r; diff --git a/src/resolve/resolved-conf.c b/src/resolve/resolved-conf.c index a25dffae630..3176692c5f8 100644 --- a/src/resolve/resolved-conf.c +++ b/src/resolve/resolved-conf.c @@ -390,11 +390,11 @@ int config_parse_dnssd_txt( assert_not_reached(); } - LIST_INSERT_AFTER(items, txt_data->txt, last, i); + LIST_INSERT_AFTER(items, txt_data->txts, last, i); last = i; } - if (!LIST_IS_EMPTY(txt_data->txt)) { + if (txt_data->txts) { LIST_PREPEND(items, s->txt_data_items, txt_data); TAKE_PTR(txt_data); } diff --git a/src/resolve/resolved-dnssd.c b/src/resolve/resolved-dnssd.c index 02462599be1..84193eacc1d 100644 --- a/src/resolve/resolved-dnssd.c +++ b/src/resolve/resolved-dnssd.c @@ -17,7 +17,7 @@ DnssdTxtData *dnssd_txtdata_free(DnssdTxtData *txt_data) { return NULL; dns_resource_record_unref(txt_data->rr); - dns_txt_item_free_all(txt_data->txt); + dns_txt_item_free_all(txt_data->txts); return mfree(txt_data); } @@ -107,12 +107,12 @@ static int dnssd_service_load(Manager *manager, const char *filename) { "%s doesn't define service type", service->name); - if (LIST_IS_EMPTY(service->txt_data_items)) { + if (!service->txt_data_items) { txt_data = new0(DnssdTxtData, 1); if (!txt_data) return log_oom(); - r = dns_txt_item_new_empty(&txt_data->txt); + r = dns_txt_item_new_empty(&txt_data->txts); if (r < 0) return r; @@ -237,7 +237,7 @@ int dnssd_update_rrs(DnssdService *s) { goto oom; txt_data->rr->ttl = MDNS_DEFAULT_TTL; - txt_data->rr->txt.items = dns_txt_item_copy(txt_data->txt); + txt_data->rr->txt.items = dns_txt_item_copy(txt_data->txts); if (!txt_data->rr->txt.items) goto oom; } diff --git a/src/resolve/resolved-dnssd.h b/src/resolve/resolved-dnssd.h index 219c0ddfea2..e978a0d5fc6 100644 --- a/src/resolve/resolved-dnssd.h +++ b/src/resolve/resolved-dnssd.h @@ -13,13 +13,13 @@ typedef struct DnsTxtItem DnsTxtItem; enum { DNS_TXT_ITEM_TEXT, - DNS_TXT_ITEM_DATA + DNS_TXT_ITEM_DATA, }; struct DnssdTxtData { DnsResourceRecord *rr; - LIST_HEAD(DnsTxtItem, txt); + LIST_HEAD(DnsTxtItem, txts); LIST_FIELDS(DnssdTxtData, items); }; diff --git a/src/systemctl/systemctl-show.c b/src/systemctl/systemctl-show.c index b24e5fd6bad..a7573786141 100644 --- a/src/systemctl/systemctl-show.c +++ b/src/systemctl/systemctl-show.c @@ -64,7 +64,7 @@ typedef struct ExecStatusInfo { ExecCommandFlags flags; - LIST_FIELDS(struct ExecStatusInfo, exec); + LIST_FIELDS(struct ExecStatusInfo, exec_status_info_list); } ExecStatusInfo; static void exec_status_info_free(ExecStatusInfo *i) { @@ -263,7 +263,7 @@ typedef struct UnitStatusInfo { uint64_t default_memory_min; uint64_t default_memory_low; - LIST_HEAD(ExecStatusInfo, exec); + LIST_HEAD(ExecStatusInfo, exec_status_info_list); } UnitStatusInfo; static void unit_status_info_free(UnitStatusInfo *info) { @@ -281,8 +281,8 @@ static void unit_status_info_free(UnitStatusInfo *info) { unit_condition_free(c); } - while ((p = info->exec)) { - LIST_REMOVE(exec, info->exec, p); + while ((p = info->exec_status_info_list)) { + LIST_REMOVE(exec_status_info_list, info->exec_status_info_list, p); exec_status_info_free(p); } } @@ -566,7 +566,7 @@ static void print_status_info( printf("\n"); } - LIST_FOREACH(exec, p, i->exec) { + LIST_FOREACH(exec_status_info_list, p, i->exec_status_info_list) { _cleanup_free_ char *argv = NULL; bool good; @@ -944,7 +944,7 @@ static int map_exec(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_e if (!info) return -ENOMEM; - LIST_FIND_TAIL(exec, i->exec, last); + LIST_FIND_TAIL(exec_status_info_list, i->exec_status_info_list, last); while ((r = exec_status_info_deserialize(m, info, is_ex_prop)) > 0) { @@ -952,7 +952,7 @@ static int map_exec(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_e if (!info->name) return -ENOMEM; - LIST_INSERT_AFTER(exec, i->exec, last, info); + LIST_INSERT_AFTER(exec_status_info_list, i->exec_status_info_list, last, info); last = info; info = new0(ExecStatusInfo, 1); diff --git a/src/test/test-list.c b/src/test/test-list.c index 78bbad8e4e0..2c764d7b711 100644 --- a/src/test/test-list.c +++ b/src/test/test-list.c @@ -6,7 +6,7 @@ int main(int argc, const char *argv[]) { size_t i; typedef struct list_item { - LIST_FIELDS(struct list_item, item); + LIST_FIELDS(struct list_item, item_list); } list_item; LIST_HEAD(list_item, head); LIST_HEAD(list_item, head2); @@ -18,243 +18,243 @@ int main(int argc, const char *argv[]) { assert_se(head2 == NULL); for (i = 0; i < ELEMENTSOF(items); i++) { - LIST_INIT(item, &items[i]); - assert_se(LIST_JUST_US(item, &items[i])); - LIST_PREPEND(item, head, &items[i]); + LIST_INIT(item_list, &items[i]); + assert_se(LIST_JUST_US(item_list, &items[i])); + LIST_PREPEND(item_list, head, &items[i]); } i = 0; - LIST_FOREACH_OTHERS(item, cursor, &items[2]) { + LIST_FOREACH_OTHERS(item_list, cursor, &items[2]) { i++; assert_se(cursor != &items[2]); } assert_se(i == ELEMENTSOF(items)-1); i = 0; - LIST_FOREACH_OTHERS(item, cursor, &items[0]) { + LIST_FOREACH_OTHERS(item_list, cursor, &items[0]) { i++; assert_se(cursor != &items[0]); } assert_se(i == ELEMENTSOF(items)-1); i = 0; - LIST_FOREACH_OTHERS(item, cursor, &items[3]) { + LIST_FOREACH_OTHERS(item_list, cursor, &items[3]) { i++; assert_se(cursor != &items[3]); } assert_se(i == ELEMENTSOF(items)-1); - assert_se(!LIST_JUST_US(item, head)); + assert_se(!LIST_JUST_US(item_list, head)); - assert_se(items[0].item_next == NULL); - assert_se(items[1].item_next == &items[0]); - assert_se(items[2].item_next == &items[1]); - assert_se(items[3].item_next == &items[2]); + assert_se(items[0].item_list_next == NULL); + assert_se(items[1].item_list_next == &items[0]); + assert_se(items[2].item_list_next == &items[1]); + assert_se(items[3].item_list_next == &items[2]); - assert_se(items[0].item_prev == &items[1]); - assert_se(items[1].item_prev == &items[2]); - assert_se(items[2].item_prev == &items[3]); - assert_se(items[3].item_prev == NULL); + assert_se(items[0].item_list_prev == &items[1]); + assert_se(items[1].item_list_prev == &items[2]); + assert_se(items[2].item_list_prev == &items[3]); + assert_se(items[3].item_list_prev == NULL); list_item *cursor; - LIST_FIND_HEAD(item, &items[0], cursor); + LIST_FIND_HEAD(item_list, &items[0], cursor); assert_se(cursor == &items[3]); - LIST_FIND_TAIL(item, &items[3], cursor); + LIST_FIND_TAIL(item_list, &items[3], cursor); assert_se(cursor == &items[0]); - LIST_REMOVE(item, head, &items[1]); - assert_se(LIST_JUST_US(item, &items[1])); + LIST_REMOVE(item_list, head, &items[1]); + assert_se(LIST_JUST_US(item_list, &items[1])); - assert_se(items[0].item_next == NULL); - assert_se(items[2].item_next == &items[0]); - assert_se(items[3].item_next == &items[2]); + assert_se(items[0].item_list_next == NULL); + assert_se(items[2].item_list_next == &items[0]); + assert_se(items[3].item_list_next == &items[2]); - assert_se(items[0].item_prev == &items[2]); - assert_se(items[2].item_prev == &items[3]); - assert_se(items[3].item_prev == NULL); + assert_se(items[0].item_list_prev == &items[2]); + assert_se(items[2].item_list_prev == &items[3]); + assert_se(items[3].item_list_prev == NULL); - LIST_INSERT_AFTER(item, head, &items[3], &items[1]); - assert_se(items[0].item_next == NULL); - assert_se(items[2].item_next == &items[0]); - assert_se(items[1].item_next == &items[2]); - assert_se(items[3].item_next == &items[1]); + LIST_INSERT_AFTER(item_list, head, &items[3], &items[1]); + assert_se(items[0].item_list_next == NULL); + assert_se(items[2].item_list_next == &items[0]); + assert_se(items[1].item_list_next == &items[2]); + assert_se(items[3].item_list_next == &items[1]); - assert_se(items[0].item_prev == &items[2]); - assert_se(items[2].item_prev == &items[1]); - assert_se(items[1].item_prev == &items[3]); - assert_se(items[3].item_prev == NULL); + assert_se(items[0].item_list_prev == &items[2]); + assert_se(items[2].item_list_prev == &items[1]); + assert_se(items[1].item_list_prev == &items[3]); + assert_se(items[3].item_list_prev == NULL); - LIST_REMOVE(item, head, &items[1]); - assert_se(LIST_JUST_US(item, &items[1])); + LIST_REMOVE(item_list, head, &items[1]); + assert_se(LIST_JUST_US(item_list, &items[1])); - assert_se(items[0].item_next == NULL); - assert_se(items[2].item_next == &items[0]); - assert_se(items[3].item_next == &items[2]); + assert_se(items[0].item_list_next == NULL); + assert_se(items[2].item_list_next == &items[0]); + assert_se(items[3].item_list_next == &items[2]); - assert_se(items[0].item_prev == &items[2]); - assert_se(items[2].item_prev == &items[3]); - assert_se(items[3].item_prev == NULL); + assert_se(items[0].item_list_prev == &items[2]); + assert_se(items[2].item_list_prev == &items[3]); + assert_se(items[3].item_list_prev == NULL); - LIST_INSERT_BEFORE(item, head, &items[2], &items[1]); - assert_se(items[0].item_next == NULL); - assert_se(items[2].item_next == &items[0]); - assert_se(items[1].item_next == &items[2]); - assert_se(items[3].item_next == &items[1]); + LIST_INSERT_BEFORE(item_list, head, &items[2], &items[1]); + assert_se(items[0].item_list_next == NULL); + assert_se(items[2].item_list_next == &items[0]); + assert_se(items[1].item_list_next == &items[2]); + assert_se(items[3].item_list_next == &items[1]); - assert_se(items[0].item_prev == &items[2]); - assert_se(items[2].item_prev == &items[1]); - assert_se(items[1].item_prev == &items[3]); - assert_se(items[3].item_prev == NULL); + assert_se(items[0].item_list_prev == &items[2]); + assert_se(items[2].item_list_prev == &items[1]); + assert_se(items[1].item_list_prev == &items[3]); + assert_se(items[3].item_list_prev == NULL); - LIST_REMOVE(item, head, &items[0]); - assert_se(LIST_JUST_US(item, &items[0])); + LIST_REMOVE(item_list, head, &items[0]); + assert_se(LIST_JUST_US(item_list, &items[0])); - assert_se(items[2].item_next == NULL); - assert_se(items[1].item_next == &items[2]); - assert_se(items[3].item_next == &items[1]); + assert_se(items[2].item_list_next == NULL); + assert_se(items[1].item_list_next == &items[2]); + assert_se(items[3].item_list_next == &items[1]); - assert_se(items[2].item_prev == &items[1]); - assert_se(items[1].item_prev == &items[3]); - assert_se(items[3].item_prev == NULL); + assert_se(items[2].item_list_prev == &items[1]); + assert_se(items[1].item_list_prev == &items[3]); + assert_se(items[3].item_list_prev == NULL); - LIST_INSERT_BEFORE(item, head, &items[3], &items[0]); - assert_se(items[2].item_next == NULL); - assert_se(items[1].item_next == &items[2]); - assert_se(items[3].item_next == &items[1]); - assert_se(items[0].item_next == &items[3]); + LIST_INSERT_BEFORE(item_list, head, &items[3], &items[0]); + assert_se(items[2].item_list_next == NULL); + assert_se(items[1].item_list_next == &items[2]); + assert_se(items[3].item_list_next == &items[1]); + assert_se(items[0].item_list_next == &items[3]); - assert_se(items[2].item_prev == &items[1]); - assert_se(items[1].item_prev == &items[3]); - assert_se(items[3].item_prev == &items[0]); - assert_se(items[0].item_prev == NULL); + assert_se(items[2].item_list_prev == &items[1]); + assert_se(items[1].item_list_prev == &items[3]); + assert_se(items[3].item_list_prev == &items[0]); + assert_se(items[0].item_list_prev == NULL); assert_se(head == &items[0]); - LIST_REMOVE(item, head, &items[0]); - assert_se(LIST_JUST_US(item, &items[0])); + LIST_REMOVE(item_list, head, &items[0]); + assert_se(LIST_JUST_US(item_list, &items[0])); - assert_se(items[2].item_next == NULL); - assert_se(items[1].item_next == &items[2]); - assert_se(items[3].item_next == &items[1]); + assert_se(items[2].item_list_next == NULL); + assert_se(items[1].item_list_next == &items[2]); + assert_se(items[3].item_list_next == &items[1]); - assert_se(items[2].item_prev == &items[1]); - assert_se(items[1].item_prev == &items[3]); - assert_se(items[3].item_prev == NULL); + assert_se(items[2].item_list_prev == &items[1]); + assert_se(items[1].item_list_prev == &items[3]); + assert_se(items[3].item_list_prev == NULL); - LIST_INSERT_BEFORE(item, head, NULL, &items[0]); - assert_se(items[0].item_next == NULL); - assert_se(items[2].item_next == &items[0]); - assert_se(items[1].item_next == &items[2]); - assert_se(items[3].item_next == &items[1]); + LIST_INSERT_BEFORE(item_list, head, NULL, &items[0]); + assert_se(items[0].item_list_next == NULL); + assert_se(items[2].item_list_next == &items[0]); + assert_se(items[1].item_list_next == &items[2]); + assert_se(items[3].item_list_next == &items[1]); - assert_se(items[0].item_prev == &items[2]); - assert_se(items[2].item_prev == &items[1]); - assert_se(items[1].item_prev == &items[3]); - assert_se(items[3].item_prev == NULL); + assert_se(items[0].item_list_prev == &items[2]); + assert_se(items[2].item_list_prev == &items[1]); + assert_se(items[1].item_list_prev == &items[3]); + assert_se(items[3].item_list_prev == NULL); - LIST_REMOVE(item, head, &items[0]); - assert_se(LIST_JUST_US(item, &items[0])); + LIST_REMOVE(item_list, head, &items[0]); + assert_se(LIST_JUST_US(item_list, &items[0])); - assert_se(items[2].item_next == NULL); - assert_se(items[1].item_next == &items[2]); - assert_se(items[3].item_next == &items[1]); + assert_se(items[2].item_list_next == NULL); + assert_se(items[1].item_list_next == &items[2]); + assert_se(items[3].item_list_next == &items[1]); - assert_se(items[2].item_prev == &items[1]); - assert_se(items[1].item_prev == &items[3]); - assert_se(items[3].item_prev == NULL); + assert_se(items[2].item_list_prev == &items[1]); + assert_se(items[1].item_list_prev == &items[3]); + assert_se(items[3].item_list_prev == NULL); - LIST_REMOVE(item, head, &items[1]); - assert_se(LIST_JUST_US(item, &items[1])); + LIST_REMOVE(item_list, head, &items[1]); + assert_se(LIST_JUST_US(item_list, &items[1])); - assert_se(items[2].item_next == NULL); - assert_se(items[3].item_next == &items[2]); + assert_se(items[2].item_list_next == NULL); + assert_se(items[3].item_list_next == &items[2]); - assert_se(items[2].item_prev == &items[3]); - assert_se(items[3].item_prev == NULL); + assert_se(items[2].item_list_prev == &items[3]); + assert_se(items[3].item_list_prev == NULL); - LIST_REMOVE(item, head, &items[2]); - assert_se(LIST_JUST_US(item, &items[2])); - assert_se(LIST_JUST_US(item, head)); + LIST_REMOVE(item_list, head, &items[2]); + assert_se(LIST_JUST_US(item_list, &items[2])); + assert_se(LIST_JUST_US(item_list, head)); - LIST_REMOVE(item, head, &items[3]); - assert_se(LIST_JUST_US(item, &items[3])); + LIST_REMOVE(item_list, head, &items[3]); + assert_se(LIST_JUST_US(item_list, &items[3])); assert_se(head == NULL); for (i = 0; i < ELEMENTSOF(items); i++) { - assert_se(LIST_JUST_US(item, &items[i])); - LIST_APPEND(item, head, &items[i]); + assert_se(LIST_JUST_US(item_list, &items[i])); + LIST_APPEND(item_list, head, &items[i]); } - assert_se(!LIST_JUST_US(item, head)); + assert_se(!LIST_JUST_US(item_list, head)); - assert_se(items[0].item_next == &items[1]); - assert_se(items[1].item_next == &items[2]); - assert_se(items[2].item_next == &items[3]); - assert_se(items[3].item_next == NULL); + assert_se(items[0].item_list_next == &items[1]); + assert_se(items[1].item_list_next == &items[2]); + assert_se(items[2].item_list_next == &items[3]); + assert_se(items[3].item_list_next == NULL); - assert_se(items[0].item_prev == NULL); - assert_se(items[1].item_prev == &items[0]); - assert_se(items[2].item_prev == &items[1]); - assert_se(items[3].item_prev == &items[2]); + assert_se(items[0].item_list_prev == NULL); + assert_se(items[1].item_list_prev == &items[0]); + assert_se(items[2].item_list_prev == &items[1]); + assert_se(items[3].item_list_prev == &items[2]); for (i = 0; i < ELEMENTSOF(items); i++) - LIST_REMOVE(item, head, &items[i]); + LIST_REMOVE(item_list, head, &items[i]); assert_se(head == NULL); for (i = 0; i < ELEMENTSOF(items) / 2; i++) { - LIST_INIT(item, &items[i]); - assert_se(LIST_JUST_US(item, &items[i])); - LIST_PREPEND(item, head, &items[i]); + LIST_INIT(item_list, &items[i]); + assert_se(LIST_JUST_US(item_list, &items[i])); + LIST_PREPEND(item_list, head, &items[i]); } for (i = ELEMENTSOF(items) / 2; i < ELEMENTSOF(items); i++) { - LIST_INIT(item, &items[i]); - assert_se(LIST_JUST_US(item, &items[i])); - LIST_PREPEND(item, head2, &items[i]); + LIST_INIT(item_list, &items[i]); + assert_se(LIST_JUST_US(item_list, &items[i])); + LIST_PREPEND(item_list, head2, &items[i]); } - assert_se(items[0].item_next == NULL); - assert_se(items[1].item_next == &items[0]); - assert_se(items[2].item_next == NULL); - assert_se(items[3].item_next == &items[2]); + assert_se(items[0].item_list_next == NULL); + assert_se(items[1].item_list_next == &items[0]); + assert_se(items[2].item_list_next == NULL); + assert_se(items[3].item_list_next == &items[2]); - assert_se(items[0].item_prev == &items[1]); - assert_se(items[1].item_prev == NULL); - assert_se(items[2].item_prev == &items[3]); - assert_se(items[3].item_prev == NULL); + assert_se(items[0].item_list_prev == &items[1]); + assert_se(items[1].item_list_prev == NULL); + assert_se(items[2].item_list_prev == &items[3]); + assert_se(items[3].item_list_prev == NULL); - LIST_JOIN(item, head2, head); + LIST_JOIN(item_list, head2, head); assert_se(head == NULL); - assert_se(items[0].item_next == NULL); - assert_se(items[1].item_next == &items[0]); - assert_se(items[2].item_next == &items[1]); - assert_se(items[3].item_next == &items[2]); + assert_se(items[0].item_list_next == NULL); + assert_se(items[1].item_list_next == &items[0]); + assert_se(items[2].item_list_next == &items[1]); + assert_se(items[3].item_list_next == &items[2]); - assert_se(items[0].item_prev == &items[1]); - assert_se(items[1].item_prev == &items[2]); - assert_se(items[2].item_prev == &items[3]); - assert_se(items[3].item_prev == NULL); + assert_se(items[0].item_list_prev == &items[1]); + assert_se(items[1].item_list_prev == &items[2]); + assert_se(items[2].item_list_prev == &items[3]); + assert_se(items[3].item_list_prev == NULL); - LIST_JOIN(item, head, head2); + LIST_JOIN(item_list, head, head2); assert_se(head2 == NULL); - assert_se(!LIST_IS_EMPTY(head)); + assert_se(head); for (i = 0; i < ELEMENTSOF(items); i++) - LIST_REMOVE(item, head, &items[i]); + LIST_REMOVE(item_list, head, &items[i]); assert_se(head == NULL); - LIST_PREPEND(item, head, items + 0); - LIST_PREPEND(item, head, items + 1); - LIST_PREPEND(item, head, items + 2); + LIST_PREPEND(item_list, head, items + 0); + LIST_PREPEND(item_list, head, items + 1); + LIST_PREPEND(item_list, head, items + 2); - assert_se(LIST_POP(item, head) == items + 2); - assert_se(LIST_POP(item, head) == items + 1); - assert_se(LIST_POP(item, head) == items + 0); - assert_se(LIST_POP(item, head) == NULL); + assert_se(LIST_POP(item_list, head) == items + 2); + assert_se(LIST_POP(item_list, head) == items + 1); + assert_se(LIST_POP(item_list, head) == items + 0); + assert_se(LIST_POP(item_list, head) == NULL); return 0; } diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index f95b751b75a..753ebb015db 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -1056,21 +1056,19 @@ static int parse_line(char **line, char **ret_key, char **ret_attr, UdevRuleOper } static void sort_tokens(UdevRuleLine *rule_line) { - UdevRuleToken *head_old; - assert(rule_line); - head_old = TAKE_PTR(rule_line->tokens); + UdevRuleToken *old_tokens = TAKE_PTR(rule_line->tokens); rule_line->current_token = NULL; - while (!LIST_IS_EMPTY(head_old)) { + while (old_tokens) { UdevRuleToken *min_token = NULL; - LIST_FOREACH(tokens, t, head_old) + LIST_FOREACH(tokens, t, old_tokens) if (!min_token || min_token->type > t->type) min_token = t; - LIST_REMOVE(tokens, head_old, min_token); + LIST_REMOVE(tokens, old_tokens, min_token); rule_line_append_token(rule_line, min_token); } } diff --git a/src/udev/udevd.c b/src/udev/udevd.c index 78c37b905e2..63f41210dde 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -942,8 +942,7 @@ static int event_queue_start(Manager *manager) { assert(manager); - if (LIST_IS_EMPTY(manager->events) || - manager->exit || manager->stop_exec_queue) + if (!manager->events || manager->exit || manager->stop_exec_queue) return 0; assert_se(sd_event_now(manager->event, CLOCK_MONOTONIC, &usec) >= 0); @@ -1121,7 +1120,7 @@ static int event_queue_insert(Manager *manager, sd_device *dev) { .state = EVENT_QUEUED, }; - if (LIST_IS_EMPTY(manager->events)) { + if (!manager->events) { r = touch("/run/udev/queue"); if (r < 0) log_warning_errno(r, "Failed to touch /run/udev/queue, ignoring: %m"); @@ -1566,7 +1565,7 @@ static int on_post(sd_event_source *s, void *userdata) { assert(manager); - if (!LIST_IS_EMPTY(manager->events)) { + if (manager->events) { /* Try to process pending events if idle workers exist. Why is this necessary? * When a worker finished an event and became idle, even if there was a pending event, * the corresponding device might have been locked and the processing of the event