mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-22 13:33:56 +03:00
basic/list: drop LIST_IS_EMPTY
This was a trivial wrapper that didn't provide any added value. With more complicated structures like strvs, hashmaps, sets, and arrays, it is possible to have an empty container. But in case of a list, the list is empty only when the head is missing. Also, we generally want the positive condition, so we replace many if (!LIST_IS_EMPTY(x)) with just if (x).
This commit is contained in:
parent
a4d60b3e1c
commit
64903d18df
@ -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); \
|
||||
|
@ -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 { \
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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. */
|
||||
|
@ -1799,7 +1799,7 @@ 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);
|
||||
@ -1862,7 +1862,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;
|
||||
@ -3874,7 +3874,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->inotify_data_buffered)
|
||||
goto pending;
|
||||
|
||||
e->state = SD_EVENT_ARMED;
|
||||
@ -3954,7 +3954,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->inotify_data_buffered)
|
||||
timeout = 0;
|
||||
|
||||
for (;;) {
|
||||
|
@ -394,7 +394,7 @@ int config_parse_dnssd_txt(
|
||||
last = i;
|
||||
}
|
||||
|
||||
if (!LIST_IS_EMPTY(txt_data->txt)) {
|
||||
if (txt_data->txt) {
|
||||
LIST_PREPEND(items, s->txt_data_items, txt_data);
|
||||
TAKE_PTR(txt_data);
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ 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();
|
||||
|
@ -240,7 +240,7 @@ int main(int argc, const char *argv[]) {
|
||||
|
||||
LIST_JOIN(item, 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]);
|
||||
|
@ -1063,7 +1063,7 @@ static void sort_tokens(UdevRuleLine *rule_line) {
|
||||
head_old = TAKE_PTR(rule_line->tokens);
|
||||
rule_line->current_token = NULL;
|
||||
|
||||
while (!LIST_IS_EMPTY(head_old)) {
|
||||
while (head_old) {
|
||||
UdevRuleToken *min_token = NULL;
|
||||
|
||||
LIST_FOREACH(tokens, t, head_old)
|
||||
|
@ -1008,8 +1008,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);
|
||||
@ -1166,7 +1165,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");
|
||||
@ -1611,7 +1610,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
|
||||
|
Loading…
Reference in New Issue
Block a user