]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic/list: drop LIST_IS_EMPTY
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 28 Jun 2022 16:37:34 +0000 (18:37 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 2 Jul 2022 10:46:16 +0000 (12:46 +0200)
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).

14 files changed:
coccinelle/macros.h
src/basic/list.h
src/core/cgroup.c
src/core/dbus-cgroup.c
src/core/dbus-execute.c
src/core/dbus-util.c
src/core/load-fragment.c
src/core/unit.c
src/libsystemd/sd-event/sd-event.c
src/resolve/resolved-conf.c
src/resolve/resolved-dnssd.c
src/test/test-list.c
src/udev/udev-rules.c
src/udev/udevd.c

index 6a0a64bb05c877130e67a46985fc148acecc7d54..f44b3f2d26f48746e0533d2e7e6902d77510a509 100644 (file)
              (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);                                              \
index 58e83a6cb2bfab17259e15428422528f4be662e6..ca300396908c8d9dba5f9133e7f55e68bb5bcbe0 100644 (file)
              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 {                                                            \
index 25707fce64250e93810ac7da4299a284a3c1a49c..0fce812b4000bdd38b7c465bfb2b16584bc52746 100644 (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) {
index 607370d7bfe7abbc5eeb68dac75910d935db58f4..7e95f0e39077b780c568da22252cc53bc6babb6e 100644 (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;
index 1a9e5da6350c9bb909d32e73182a5db42e31171d..8de092ee4e23054aa6d43add41f09ea3ec54a8b1 100644 (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);
                         }
                 }
 
index 32a2ec0ff901992104173fea502f977cccbef289..264a4f55b67db379634c59ec8002fb04a2af4cd7 100644 (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)
index 3ff6eae8fcead70372fba074553462131d90f688..313f667cd795c8fa8ead1213da40820f57e56358 100644 (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;
 }
index 180dccc2b291f85ec49a8f8a68408582626a0893..40fc79995adc63910c4bc9763a0cc0cd006a388f 100644 (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. */
index a37147d1d550555f94eecc040831c5592eaa9002..5833a8334636c6505867017aee223678b28c13c6 100644 (file)
@@ -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 (;;) {
index a25dffae630ae074c292c8c6bc356a351a02a8c7..babd19b925fa0a0edceff8a9b3fb147a475ac0a8 100644 (file)
@@ -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);
         }
index 9c2594c1ba01b5ab15aff060fd2b9e636a0ac4ea..169c942308a9f5c1ec158e4d6ae431f1a429c1a7 100644 (file)
@@ -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();
index 78bbad8e4e001f4c11cfba41a24dcc2ff3c2febf..dc7ecb7572e94f9071adfe5ab9905c2d6267591b 100644 (file)
@@ -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]);
index f95b751b75ae89388a5a8273b6d60a6ce7035dab..9bbf797acd2dd4aca02a3379c41a597e5fcf5842 100644 (file)
@@ -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)
index 1994b6b2d523febebb287953326be109e448f84e..d3e949dae4b27672fcd617cb49ec4d2a6196e529 100644 (file)
@@ -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