richardphibel / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
ac3a84
From 883e46f2e4255b92a338c9d4004a8b4740cdbcaf Mon Sep 17 00:00:00 2001
ac3a84
From: Yu Watanabe <watanabe.yu+github@gmail.com>
ac3a84
Date: Tue, 15 Nov 2022 22:59:01 +0900
ac3a84
Subject: [PATCH] core/unit: fix log message
ac3a84
ac3a84
As you can see in the below, the dropped dependency Before=issue-24990.service
ac3a84
is not logged, but the dependency Before=test1.service which is not owned by
ac3a84
the units generated by the TEST-26 is logged.
ac3a84
ac3a84
Before:
ac3a84
systemd[1]: issue-24990.service: Dependency After=test1.service dropped, merged into issue-24990.service
ac3a84
systemd[1]: issue-24990.service: Dependency Before=test1.service dropped, merged into issue-24990.service
ac3a84
ac3a84
After:
ac3a84
systemd[1]: issue-24990.service: Dependency After=test1.service is dropped, as test1.service is merged into issue-24990.service.
ac3a84
systemd[1]: issue-24990.service: Dependency Before=issue-24990.service in test1.service is dropped, as test1.service is merged into issue-24990.service.
ac3a84
ac3a84
(cherry picked from commit ed9911630e4bca844381d7caeb850dad9a9fa122)
ac3a84
ac3a84
Related: #2160477
ac3a84
---
ac3a84
 src/core/unit.c | 49 ++++++++++++++++++++++---------------------------
ac3a84
 1 file changed, 22 insertions(+), 27 deletions(-)
ac3a84
ac3a84
diff --git a/src/core/unit.c b/src/core/unit.c
ac3a84
index d1929bbf69..c319e99d71 100644
ac3a84
--- a/src/core/unit.c
ac3a84
+++ b/src/core/unit.c
ac3a84
@@ -936,29 +936,17 @@ static int unit_reserve_dependencies(Unit *u, Unit *other) {
ac3a84
         return 0;
ac3a84
 }
ac3a84
 
ac3a84
-static void unit_maybe_warn_about_dependency(
ac3a84
-                Unit *u,
ac3a84
-                const char *other_id,
ac3a84
-                UnitDependency dependency) {
ac3a84
-
ac3a84
-        assert(u);
ac3a84
-
ac3a84
+static bool unit_should_warn_about_dependency(UnitDependency dependency) {
ac3a84
         /* Only warn about some unit types */
ac3a84
-        if (!IN_SET(dependency,
ac3a84
-                    UNIT_CONFLICTS,
ac3a84
-                    UNIT_CONFLICTED_BY,
ac3a84
-                    UNIT_BEFORE,
ac3a84
-                    UNIT_AFTER,
ac3a84
-                    UNIT_ON_SUCCESS,
ac3a84
-                    UNIT_ON_FAILURE,
ac3a84
-                    UNIT_TRIGGERS,
ac3a84
-                    UNIT_TRIGGERED_BY))
ac3a84
-                return;
ac3a84
-
ac3a84
-        if (streq_ptr(u->id, other_id))
ac3a84
-                log_unit_warning(u, "Dependency %s=%s dropped", unit_dependency_to_string(dependency), u->id);
ac3a84
-        else
ac3a84
-                log_unit_warning(u, "Dependency %s=%s dropped, merged into %s", unit_dependency_to_string(dependency), strna(other_id), u->id);
ac3a84
+        return IN_SET(dependency,
ac3a84
+                      UNIT_CONFLICTS,
ac3a84
+                      UNIT_CONFLICTED_BY,
ac3a84
+                      UNIT_BEFORE,
ac3a84
+                      UNIT_AFTER,
ac3a84
+                      UNIT_ON_SUCCESS,
ac3a84
+                      UNIT_ON_FAILURE,
ac3a84
+                      UNIT_TRIGGERS,
ac3a84
+                      UNIT_TRIGGERED_BY);
ac3a84
 }
ac3a84
 
ac3a84
 static int unit_per_dependency_type_hashmap_update(
ac3a84
@@ -1056,8 +1044,10 @@ static void unit_merge_dependencies(Unit *u, Unit *other) {
ac3a84
 
ac3a84
         /* First, remove dependency to other. */
ac3a84
         HASHMAP_FOREACH_KEY(deps, dt, u->dependencies) {
ac3a84
-                if (hashmap_remove(deps, other))
ac3a84
-                        unit_maybe_warn_about_dependency(u, other->id, UNIT_DEPENDENCY_FROM_PTR(dt));
ac3a84
+                if (hashmap_remove(deps, other) && unit_should_warn_about_dependency(UNIT_DEPENDENCY_FROM_PTR(dt)))
ac3a84
+                        log_unit_warning(u, "Dependency %s=%s is dropped, as %s is merged into %s.",
ac3a84
+                                         unit_dependency_to_string(UNIT_DEPENDENCY_FROM_PTR(dt)),
ac3a84
+                                         other->id, other->id, u->id);
ac3a84
 
ac3a84
                 if (hashmap_isempty(deps))
ac3a84
                         hashmap_free(hashmap_remove(u->dependencies, dt));
ac3a84
@@ -1084,7 +1074,11 @@ static void unit_merge_dependencies(Unit *u, Unit *other) {
ac3a84
                         if (back == u) {
ac3a84
                                 /* This is a dependency pointing back to the unit we want to merge with?
ac3a84
                                  * Suppress it (but warn) */
ac3a84
-                                unit_maybe_warn_about_dependency(u, other->id, UNIT_DEPENDENCY_FROM_PTR(dt));
ac3a84
+                                if (unit_should_warn_about_dependency(UNIT_DEPENDENCY_FROM_PTR(dt)))
ac3a84
+                                        log_unit_warning(u, "Dependency %s=%s in %s is dropped, as %s is merged into %s.",
ac3a84
+                                                         unit_dependency_to_string(UNIT_DEPENDENCY_FROM_PTR(dt)),
ac3a84
+                                                         u->id, other->id, other->id, u->id);
ac3a84
+
ac3a84
                                 hashmap_remove(other_deps, back);
ac3a84
                                 continue;
ac3a84
                         }
ac3a84
@@ -3049,7 +3043,6 @@ int unit_add_dependency(
ac3a84
                 [UNIT_IN_SLICE]               = UNIT_SLICE_OF,
ac3a84
                 [UNIT_SLICE_OF]               = UNIT_IN_SLICE,
ac3a84
         };
ac3a84
-        Unit *original_u = u, *original_other = other;
ac3a84
         UnitDependencyAtom a;
ac3a84
         int r;
ac3a84
 
ac3a84
@@ -3068,7 +3061,9 @@ int unit_add_dependency(
ac3a84
 
ac3a84
         /* We won't allow dependencies on ourselves. We will not consider them an error however. */
ac3a84
         if (u == other) {
ac3a84
-                unit_maybe_warn_about_dependency(original_u, original_other->id, d);
ac3a84
+                if (unit_should_warn_about_dependency(d))
ac3a84
+                        log_unit_warning(u, "Dependency %s=%s is dropped.",
ac3a84
+                                         unit_dependency_to_string(d), u->id);
ac3a84
                 return 0;
ac3a84
         }
ac3a84