Blob Blame History Raw
From 71c1119e2fe9bc57e0efb07f784f616a98763028 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Renaud=20M=C3=A9trich?= <rmetrich@redhat.com>
Date: Fri, 2 Oct 2020 17:30:35 +0200
Subject: [PATCH] unit: don't emit PropertiesChanged signal if adding a
 dependency to a unit is a no-op

(cherry-picked from commit 5177cb0a9add4ae568cff6e6f7c2b3c77760c343)

Related: #1793527
---
 src/core/unit.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/core/unit.c b/src/core/unit.c
index 18b1b898fd..e07c34bfc5 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -2260,6 +2260,9 @@ int unit_add_dependency(Unit *u, UnitDependency d, Unit *other, bool add_referen
         };
         int r, q = 0, v = 0, w = 0;
         Unit *orig_u = u, *orig_other = other;
+        /* Helper to know whether sending a notification is necessary or not:
+         * if the dependency is already there, no need to notify! */
+        bool noop = true;
 
         assert(u);
         assert(d >= 0 && d < _UNIT_DEPENDENCY_MAX);
@@ -2298,13 +2301,16 @@ int unit_add_dependency(Unit *u, UnitDependency d, Unit *other, bool add_referen
         q = set_put(u->dependencies[d], other);
         if (q < 0)
                 return q;
+        else if (q > 0)
+                noop = false;
 
         if (inverse_table[d] != _UNIT_DEPENDENCY_INVALID && inverse_table[d] != d) {
                 v = set_put(other->dependencies[inverse_table[d]], u);
                 if (v < 0) {
                         r = v;
                         goto fail;
-                }
+                } else if (v > 0)
+                        noop = false;
         }
 
         if (add_reference) {
@@ -2312,14 +2318,18 @@ int unit_add_dependency(Unit *u, UnitDependency d, Unit *other, bool add_referen
                 if (w < 0) {
                         r = w;
                         goto fail;
-                }
+                } else if (w > 0)
+                        noop = false;
 
                 r = set_put(other->dependencies[UNIT_REFERENCED_BY], u);
                 if (r < 0)
                         goto fail;
+                else if (r > 0)
+                        noop = false;
         }
 
-        unit_add_to_dbus_queue(u);
+        if (!noop)
+                unit_add_to_dbus_queue(u);
         return 0;
 
 fail: