timedate: increment reference count of sd_bus_message
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 21 Jul 2018 14:07:53 +0000 (23:07 +0900)
committerMichael Biebl <biebl@debian.org>
Tue, 20 Nov 2018 18:44:39 +0000 (18:44 +0000)
The commit 5d280742b645a69a19e7f9131adc0c95f5c7fa07 introduces a
barrier to suppress calling context_update_ntp_status() multiple times.
However, it just stores the address of sd_bus_message object. So,
when an address is reused on the subsequent message, then the status
of NTP clients are not updated.

This makes the stored message object is referenced by the context
object. So, the subsequent message is on cirtainly different address.

(cherry picked from commit 2770af85ac04fd14af2f6bcdf4d3967ed6f2e36f)

Gbp-Pq: Name timedate-increment-reference-count-of-sd_bus_message.patch

src/timedate/timedated.c

index 82eb213e9551926bfd4acf868dff8e700d830966..a66ea22dabd298b370ad49fce729576bd62cce68 100644 (file)
@@ -43,6 +43,7 @@ typedef struct Context {
         char *zone;
         bool local_rtc;
         Hashmap *polkit_registry;
+        sd_bus_message *cache;
 
         LIST_HEAD(UnitStatusInfo, units);
 } Context;
@@ -70,6 +71,7 @@ static void context_free(Context *c) {
 
         free(c->zone);
         bus_verify_polkit_async_registry_free(c->polkit_registry);
+        sd_bus_message_unref(c->cache);
 
         while ((p = c->units)) {
                 LIST_REMOVE(units, c->units, p);
@@ -301,18 +303,20 @@ static int context_update_ntp_status(Context *c, sd_bus *bus, sd_bus_message *m)
                 { "UnitFileState", "s", NULL, offsetof(UnitStatusInfo, unit_file_state) },
                 {}
         };
-        static sd_bus_message *_m = NULL;
         UnitStatusInfo *u;
         int r;
 
         assert(c);
         assert(bus);
 
-        /* Suppress multiple call of context_update_ntp_status() within single DBus transaction. */
-        if (m && m == _m)
-                return 0;
+        /* Suppress calling context_update_ntp_status() multiple times within single DBus transaction. */
+        if (m) {
+                if (m == c->cache)
+                        return 0;
 
-        _m = m;
+                sd_bus_message_unref(c->cache);
+                c->cache = sd_bus_message_ref(m);
+        }
 
         LIST_FOREACH(units, u, c->units) {
                 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;