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