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:
Zbigniew Jędrzejewski-Szmek
2022-07-02 12:46:16 +02:00
parent a4d60b3e1c
commit 64903d18df
14 changed files with 23 additions and 29 deletions
+1 -1
View File
@@ -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) {
+1 -1
View File
@@ -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;
+4 -4
View File
@@ -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);
}
}
+1 -1
View File
@@ -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)
+4 -4
View File
@@ -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;
}
+1 -1
View File
@@ -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. */