systemd/backport-core-unit-fix-notification-about-unit-dependency-cha.patch
wangyuhang a4f95d3244 sync patch from systemd community
(cherry picked from commit 88369f234ec01b60fb047caf87b90ef10a92b0db)
2023-10-10 10:04:24 +08:00

74 lines
2.5 KiB
Diff

From ac17080c040481c35bdfa10d4e08da76175fe9d7 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Tue, 31 May 2022 01:43:15 +0900
Subject: [PATCH] core/unit: fix notification about unit dependency change
This also makes unit_add_dependency() return 1 only when a dependency
is added.
Conflict:NA
Reference:https://github.com/systemd/systemd-stable/commit/ac17080c040481c35bdfa10d4e08da76175fe9d7
---
src/core/unit.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/src/core/unit.c b/src/core/unit.c
index fd95e02153..b00d4d0e36 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -3062,7 +3062,7 @@ int unit_add_dependency(
/* Helper to know whether sending a notification is necessary or not: if the dependency is already
* there, no need to notify! */
- bool noop;
+ bool notify, notify_other = false;
assert(u);
assert(d >= 0 && d < _UNIT_DEPENDENCY_MAX);
@@ -3119,34 +3119,33 @@ int unit_add_dependency(
r = unit_add_dependency_hashmap(&u->dependencies, d, other, mask, 0);
if (r < 0)
return r;
- noop = !r;
+ notify = r > 0;
if (inverse_table[d] != _UNIT_DEPENDENCY_INVALID && inverse_table[d] != d) {
r = unit_add_dependency_hashmap(&other->dependencies, inverse_table[d], u, 0, mask);
if (r < 0)
return r;
- if (r)
- noop = false;
+ notify_other = r > 0;
}
if (add_reference) {
r = unit_add_dependency_hashmap(&u->dependencies, UNIT_REFERENCES, other, mask, 0);
if (r < 0)
return r;
- if (r)
- noop = false;
+ notify = notify || r > 0;
r = unit_add_dependency_hashmap(&other->dependencies, UNIT_REFERENCED_BY, u, 0, mask);
if (r < 0)
return r;
- if (r)
- noop = false;
+ notify_other = notify_other || r > 0;
}
- if (!noop)
+ if (notify)
unit_add_to_dbus_queue(u);
+ if (notify_other)
+ unit_add_to_dbus_queue(other);
- return 1;
+ return notify || notify_other;
}
int unit_add_two_dependencies(Unit *u, UnitDependency d, UnitDependency e, Unit *other, bool add_reference, UnitDependencyMask mask) {
--
2.33.0