mirror of
https://github.com/systemd/systemd.git
synced 2025-02-01 09:47:35 +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) != (p); \
|
||||||
(i) = (i)->name##_next ? (i)->name##_next : (head))
|
(i) = (i)->name##_next ? (i)->name##_next : (head))
|
||||||
|
|
||||||
#define LIST_IS_EMPTY(head) \
|
|
||||||
(!(head))
|
|
||||||
#define LIST_JOIN(name,a,b) \
|
#define LIST_JOIN(name,a,b) \
|
||||||
do { \
|
do { \
|
||||||
assert(b); \
|
assert(b); \
|
||||||
|
@ -170,9 +170,6 @@
|
|||||||
i != (p); \
|
i != (p); \
|
||||||
i = i->name##_next ? i->name##_next : (head))
|
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 */
|
/* 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) \
|
#define LIST_JOIN(name,a,b) \
|
||||||
do { \
|
do { \
|
||||||
|
@ -1689,7 +1689,7 @@ static bool unit_get_needs_bpf_foreign_program(Unit *u) {
|
|||||||
if (!c)
|
if (!c)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return !LIST_IS_EMPTY(c->bpf_foreign_programs);
|
return !!c->bpf_foreign_programs;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool unit_get_needs_socket_bind(Unit *u) {
|
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);
|
unit_write_setting(u, flags, name, buf);
|
||||||
|
|
||||||
if (!LIST_IS_EMPTY(c->bpf_foreign_programs)) {
|
if (c->bpf_foreign_programs) {
|
||||||
r = bpf_foreign_supported();
|
r = bpf_foreign_supported();
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
@ -1698,16 +1698,16 @@ int bus_exec_context_set_transient_property(
|
|||||||
return r;
|
return r;
|
||||||
|
|
||||||
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
|
||||||
if (LIST_IS_EMPTY(options)) {
|
if (options) {
|
||||||
c->root_image_options = mount_options_free_all(c->root_image_options);
|
|
||||||
unit_write_settingf(u, flags, name, "%s=", name);
|
|
||||||
} else {
|
|
||||||
LIST_JOIN(mount_options, c->root_image_options, options);
|
LIST_JOIN(mount_options, c->root_image_options, options);
|
||||||
unit_write_settingf(
|
unit_write_settingf(
|
||||||
u, flags|UNIT_ESCAPE_SPECIFIERS, name,
|
u, flags|UNIT_ESCAPE_SPECIFIERS, name,
|
||||||
"%s=%s",
|
"%s=%s",
|
||||||
name,
|
name,
|
||||||
format_str);
|
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)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
if (!LIST_IS_EMPTY(options)) {
|
if (options) {
|
||||||
if (ret_format_str) {
|
if (ret_format_str) {
|
||||||
char *final = strjoin(*ret_format_str, !isempty(*ret_format_str) ? separator : "", format_str);
|
char *final = strjoin(*ret_format_str, !isempty(*ret_format_str) ? separator : "", format_str);
|
||||||
if (!final)
|
if (!final)
|
||||||
|
@ -1691,11 +1691,11 @@ int config_parse_root_image_options(
|
|||||||
LIST_APPEND(mount_options, options, TAKE_PTR(o));
|
LIST_APPEND(mount_options, options, TAKE_PTR(o));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* empty spaces/separators only */
|
if (options)
|
||||||
if (LIST_IS_EMPTY(options))
|
|
||||||
c->root_image_options = mount_options_free_all(c->root_image_options);
|
|
||||||
else
|
|
||||||
LIST_JOIN(mount_options, c->root_image_options, 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;
|
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_AUTO)
|
||||||
cc->device_policy = CGROUP_DEVICE_POLICY_CLOSED;
|
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)) {
|
(cc->device_policy != CGROUP_DEVICE_POLICY_AUTO || cc->device_allow)) {
|
||||||
|
|
||||||
/* When RootImage= or MountImages= is specified, the following devices are touched. */
|
/* When RootImage= or MountImages= is specified, the following devices are touched. */
|
||||||
|
@ -1799,7 +1799,7 @@ static void event_free_inode_data(
|
|||||||
if (!d)
|
if (!d)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
assert(LIST_IS_EMPTY(d->event_sources));
|
assert(!d->event_sources);
|
||||||
|
|
||||||
if (d->fd >= 0) {
|
if (d->fd >= 0) {
|
||||||
LIST_REMOVE(to_close, e->inode_data_to_close, d);
|
LIST_REMOVE(to_close, e->inode_data_to_close, d);
|
||||||
@ -1862,7 +1862,7 @@ static void event_gc_inode_data(
|
|||||||
if (!d)
|
if (!d)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!LIST_IS_EMPTY(d->event_sources))
|
if (d->event_sources)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
inotify_data = d->inotify_data;
|
inotify_data = d->inotify_data;
|
||||||
@ -3874,7 +3874,7 @@ _public_ int sd_event_prepare(sd_event *e) {
|
|||||||
|
|
||||||
event_close_inode_data_fds(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;
|
goto pending;
|
||||||
|
|
||||||
e->state = SD_EVENT_ARMED;
|
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);
|
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 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;
|
timeout = 0;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -394,7 +394,7 @@ int config_parse_dnssd_txt(
|
|||||||
last = i;
|
last = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!LIST_IS_EMPTY(txt_data->txt)) {
|
if (txt_data->txt) {
|
||||||
LIST_PREPEND(items, s->txt_data_items, txt_data);
|
LIST_PREPEND(items, s->txt_data_items, txt_data);
|
||||||
TAKE_PTR(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",
|
"%s doesn't define service type",
|
||||||
service->name);
|
service->name);
|
||||||
|
|
||||||
if (LIST_IS_EMPTY(service->txt_data_items)) {
|
if (!service->txt_data_items) {
|
||||||
txt_data = new0(DnssdTxtData, 1);
|
txt_data = new0(DnssdTxtData, 1);
|
||||||
if (!txt_data)
|
if (!txt_data)
|
||||||
return log_oom();
|
return log_oom();
|
||||||
|
@ -240,7 +240,7 @@ int main(int argc, const char *argv[]) {
|
|||||||
|
|
||||||
LIST_JOIN(item, head, head2);
|
LIST_JOIN(item, head, head2);
|
||||||
assert_se(head2 == NULL);
|
assert_se(head2 == NULL);
|
||||||
assert_se(!LIST_IS_EMPTY(head));
|
assert_se(head);
|
||||||
|
|
||||||
for (i = 0; i < ELEMENTSOF(items); i++)
|
for (i = 0; i < ELEMENTSOF(items); i++)
|
||||||
LIST_REMOVE(item, head, &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);
|
head_old = TAKE_PTR(rule_line->tokens);
|
||||||
rule_line->current_token = NULL;
|
rule_line->current_token = NULL;
|
||||||
|
|
||||||
while (!LIST_IS_EMPTY(head_old)) {
|
while (head_old) {
|
||||||
UdevRuleToken *min_token = NULL;
|
UdevRuleToken *min_token = NULL;
|
||||||
|
|
||||||
LIST_FOREACH(tokens, t, head_old)
|
LIST_FOREACH(tokens, t, head_old)
|
||||||
|
@ -1008,8 +1008,7 @@ static int event_queue_start(Manager *manager) {
|
|||||||
|
|
||||||
assert(manager);
|
assert(manager);
|
||||||
|
|
||||||
if (LIST_IS_EMPTY(manager->events) ||
|
if (!manager->events || manager->exit || manager->stop_exec_queue)
|
||||||
manager->exit || manager->stop_exec_queue)
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
assert_se(sd_event_now(manager->event, CLOCK_MONOTONIC, &usec) >= 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,
|
.state = EVENT_QUEUED,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (LIST_IS_EMPTY(manager->events)) {
|
if (!manager->events) {
|
||||||
r = touch("/run/udev/queue");
|
r = touch("/run/udev/queue");
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
log_warning_errno(r, "Failed to touch /run/udev/queue, ignoring: %m");
|
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);
|
assert(manager);
|
||||||
|
|
||||||
if (!LIST_IS_EMPTY(manager->events)) {
|
if (manager->events) {
|
||||||
/* Try to process pending events if idle workers exist. Why is this necessary?
|
/* 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,
|
* 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
|
* the corresponding device might have been locked and the processing of the event
|
||||||
|
Loading…
x
Reference in New Issue
Block a user