]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved: make dns_transaction_gc return a pointer
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 16 Feb 2021 13:10:28 +0000 (14:10 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 16 Feb 2021 13:27:59 +0000 (14:27 +0100)
_gc() does cleanup if it is possible. So far it returned a bool to
signal if it succeeded (false on success). When working on the resolved
code I had to look at the definition every time, because the (arguably
reversed) calling convention is unobvious. So let's return a pointer
(non-NULL: gc has not been done, NULL: gc has been done).

This fits nicely with the standard to return a pointer from all free
functions obviously.

src/resolve/resolved-dns-transaction.c
src/resolve/resolved-dns-transaction.h

index bd73aa5451e899b0200308ce5e892cce1b5a9da8..e1ff503929d1db2147e17974e93c96e85ccab4a0 100644 (file)
@@ -141,23 +141,23 @@ DnsTransaction* dns_transaction_free(DnsTransaction *t) {
 
 DEFINE_TRIVIAL_CLEANUP_FUNC(DnsTransaction*, dns_transaction_free);
 
-bool dns_transaction_gc(DnsTransaction *t) {
+DnsTransaction* dns_transaction_gc(DnsTransaction *t) {
         assert(t);
 
+        /* Returns !NULL if we can't gc yet. */
+
         if (t->block_gc > 0)
-                return true;
+                return t;
 
         if (set_isempty(t->notify_query_candidates) &&
             set_isempty(t->notify_query_candidates_done) &&
             set_isempty(t->notify_zone_items) &&
             set_isempty(t->notify_zone_items_done) &&
             set_isempty(t->notify_transactions) &&
-            set_isempty(t->notify_transactions_done)) {
-                dns_transaction_free(t);
-                return false;
-        }
+            set_isempty(t->notify_transactions_done))
+                return dns_transaction_free(t);
 
-        return true;
+        return t;
 }
 
 static uint16_t pick_new_id(Manager *m) {
index 9376d504bfee9e382d358fd579dc3d6d2d106f00..3632daeb1529e9f79e10bad357e0e59f4cc74d4e 100644 (file)
@@ -143,7 +143,7 @@ struct DnsTransaction {
 int dns_transaction_new(DnsTransaction **ret, DnsScope *s, DnsResourceKey *key, DnsPacket *bypass, uint64_t flags);
 DnsTransaction* dns_transaction_free(DnsTransaction *t);
 
-bool dns_transaction_gc(DnsTransaction *t);
+DnsTransaction* dns_transaction_gc(DnsTransaction *t);
 DEFINE_TRIVIAL_CLEANUP_FUNC(DnsTransaction*, dns_transaction_gc);
 
 int dns_transaction_go(DnsTransaction *t);