!395 从systemd原生社区中同步补丁
From: @hongjinghao Reviewed-by: @licunlong Signed-off-by: @licunlong
This commit is contained in:
commit
d0cadc81ef
@ -0,0 +1,35 @@
|
||||
From 73be22c6f245ad86ef33d95bd4ab0a8e9fd121be Mon Sep 17 00:00:00 2001
|
||||
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
||||
Date: Fri, 3 Feb 2023 18:29:36 +0900
|
||||
Subject: [PATCH] argv-util: also update program_invocation_short_name
|
||||
|
||||
Our logging uses program_invocation_short_name. Without this patch,
|
||||
logs from forked client may become broken; spuriously truncated or
|
||||
the short invocation name is not completely shown in the log.
|
||||
|
||||
(cherry picked from commit dd15e4cb57129b915e01495e113696bfe0b70214)
|
||||
(cherry picked from commit ce4726468dc02bd7383cd7d90c8769576c6973e3)
|
||||
(cherry picked from commit 7a862d9d1a7196a5576720959849f45fc68b041c)
|
||||
(cherry picked from commit 9fbbd7bf28e5362b786e152a9ce4e8bd40621759)
|
||||
---
|
||||
src/basic/process-util.c | 4 ++++
|
||||
1 file changed, 4 insertions(+)
|
||||
|
||||
diff --git a/src/basic/process-util.c b/src/basic/process-util.c
|
||||
index b76ca6f7c5..10651a4564 100644
|
||||
--- a/src/basic/process-util.c
|
||||
+++ b/src/basic/process-util.c
|
||||
@@ -371,6 +371,10 @@ int rename_process(const char name[]) {
|
||||
strncpy(program_invocation_name, name, k);
|
||||
if (l > k)
|
||||
truncated = true;
|
||||
+
|
||||
+ /* Also update the short name. */
|
||||
+ char *p = strrchr(program_invocation_name, '/');
|
||||
+ program_invocation_short_name = p ? p + 1 : program_invocation_name;
|
||||
}
|
||||
|
||||
/* Third step, completely replace the argv[] array the kernel maintains for us. This requires privileges, but
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -0,0 +1,65 @@
|
||||
From c8b3b524134539846917269ddd644ee93a35623f Mon Sep 17 00:00:00 2001
|
||||
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
||||
Date: Wed, 16 Nov 2022 03:08:22 +0900
|
||||
Subject: [PATCH] core/unit: drop dependency to the unit being merged
|
||||
|
||||
Fixes a bug in 15ed3c3a188cf7fa5a60ae508fc7a3ed048d2220.
|
||||
|
||||
Fixes #24990. Also, hopefully fixes #24577.
|
||||
---
|
||||
src/core/unit.c | 21 +++++++++++++--------
|
||||
1 file changed, 13 insertions(+), 8 deletions(-)
|
||||
|
||||
diff --git a/src/core/unit.c b/src/core/unit.c
|
||||
index 36e3afd7fb..1a580157af 100644
|
||||
--- a/src/core/unit.c
|
||||
+++ b/src/core/unit.c
|
||||
@@ -1044,10 +1044,10 @@ static int unit_add_dependency_hashmap(
|
||||
return unit_per_dependency_type_hashmap_update(per_type, other, origin_mask, destination_mask);
|
||||
}
|
||||
|
||||
-static void unit_merge_dependencies(
|
||||
- Unit *u,
|
||||
- Unit *other) {
|
||||
-
|
||||
+static void unit_merge_dependencies(Unit *u, Unit *other) {
|
||||
+ Hashmap *deps;
|
||||
+ void *dt; /* Actually of type UnitDependency, except that we don't bother casting it here,
|
||||
+ * since the hashmaps all want it as void pointer. */
|
||||
int r;
|
||||
|
||||
assert(u);
|
||||
@@ -1056,12 +1056,19 @@ static void unit_merge_dependencies(
|
||||
if (u == other)
|
||||
return;
|
||||
|
||||
+ /* First, remove dependency to other. */
|
||||
+ HASHMAP_FOREACH_KEY(deps, dt, u->dependencies) {
|
||||
+ if (hashmap_remove(deps, other))
|
||||
+ unit_maybe_warn_about_dependency(u, other->id, UNIT_DEPENDENCY_FROM_PTR(dt));
|
||||
+
|
||||
+ if (hashmap_isempty(deps))
|
||||
+ hashmap_free(hashmap_remove(u->dependencies, dt));
|
||||
+ }
|
||||
+
|
||||
for (;;) {
|
||||
_cleanup_(hashmap_freep) Hashmap *other_deps = NULL;
|
||||
UnitDependencyInfo di_back;
|
||||
Unit *back;
|
||||
- void *dt; /* Actually of type UnitDependency, except that we don't bother casting it here,
|
||||
- * since the hashmaps all want it as void pointer. */
|
||||
|
||||
/* Let's focus on one dependency type at a time, that 'other' has defined. */
|
||||
other_deps = hashmap_steal_first_key_and_value(other->dependencies, &dt);
|
||||
@@ -1103,8 +1110,6 @@ static void unit_merge_dependencies(
|
||||
* them per type wholesale. */
|
||||
r = hashmap_put(u->dependencies, dt, other_deps);
|
||||
if (r == -EEXIST) {
|
||||
- Hashmap *deps;
|
||||
-
|
||||
/* The target unit already has dependencies of this type, let's then merge this individually. */
|
||||
|
||||
assert_se(deps = hashmap_get(u->dependencies, dt));
|
||||
--
|
||||
2.27.0
|
||||
|
||||
112
backport-core-unit-fix-log-message.patch
Normal file
112
backport-core-unit-fix-log-message.patch
Normal file
@ -0,0 +1,112 @@
|
||||
From ed9911630e4bca844381d7caeb850dad9a9fa122 Mon Sep 17 00:00:00 2001
|
||||
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
||||
Date: Tue, 15 Nov 2022 22:59:01 +0900
|
||||
Subject: [PATCH] core/unit: fix log message
|
||||
|
||||
As you can see in the below, the dropped dependency Before=issue-24990.service
|
||||
is not logged, but the dependency Before=test1.service which is not owned by
|
||||
the units generated by the TEST-26 is logged.
|
||||
|
||||
Before:
|
||||
systemd[1]: issue-24990.service: Dependency After=test1.service dropped, merged into issue-24990.service
|
||||
systemd[1]: issue-24990.service: Dependency Before=test1.service dropped, merged into issue-24990.service
|
||||
|
||||
After:
|
||||
systemd[1]: issue-24990.service: Dependency After=test1.service is dropped, as test1.service is merged into issue-24990.service.
|
||||
systemd[1]: issue-24990.service: Dependency Before=issue-24990.service in test1.service is dropped, as test1.service is merged into issue-24990.service.
|
||||
---
|
||||
src/core/unit.c | 49 ++++++++++++++++++++++---------------------------
|
||||
1 file changed, 22 insertions(+), 27 deletions(-)
|
||||
|
||||
diff --git a/src/core/unit.c b/src/core/unit.c
|
||||
index ea09416be5..988ba8e34a 100644
|
||||
--- a/src/core/unit.c
|
||||
+++ b/src/core/unit.c
|
||||
@@ -937,29 +937,17 @@ static int unit_reserve_dependencies(Unit *u, Unit *other) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
-static void unit_maybe_warn_about_dependency(
|
||||
- Unit *u,
|
||||
- const char *other_id,
|
||||
- UnitDependency dependency) {
|
||||
-
|
||||
- assert(u);
|
||||
-
|
||||
+static bool unit_should_warn_about_dependency(UnitDependency dependency) {
|
||||
/* Only warn about some unit types */
|
||||
- if (!IN_SET(dependency,
|
||||
- UNIT_CONFLICTS,
|
||||
- UNIT_CONFLICTED_BY,
|
||||
- UNIT_BEFORE,
|
||||
- UNIT_AFTER,
|
||||
- UNIT_ON_SUCCESS,
|
||||
- UNIT_ON_FAILURE,
|
||||
- UNIT_TRIGGERS,
|
||||
- UNIT_TRIGGERED_BY))
|
||||
- return;
|
||||
-
|
||||
- if (streq_ptr(u->id, other_id))
|
||||
- log_unit_warning(u, "Dependency %s=%s dropped", unit_dependency_to_string(dependency), u->id);
|
||||
- else
|
||||
- log_unit_warning(u, "Dependency %s=%s dropped, merged into %s", unit_dependency_to_string(dependency), strna(other_id), u->id);
|
||||
+ return IN_SET(dependency,
|
||||
+ UNIT_CONFLICTS,
|
||||
+ UNIT_CONFLICTED_BY,
|
||||
+ UNIT_BEFORE,
|
||||
+ UNIT_AFTER,
|
||||
+ UNIT_ON_SUCCESS,
|
||||
+ UNIT_ON_FAILURE,
|
||||
+ UNIT_TRIGGERS,
|
||||
+ UNIT_TRIGGERED_BY);
|
||||
}
|
||||
|
||||
static int unit_per_dependency_type_hashmap_update(
|
||||
@@ -1057,8 +1045,10 @@ static void unit_merge_dependencies(Unit *u, Unit *other) {
|
||||
|
||||
/* First, remove dependency to other. */
|
||||
HASHMAP_FOREACH_KEY(deps, dt, u->dependencies) {
|
||||
- if (hashmap_remove(deps, other))
|
||||
- unit_maybe_warn_about_dependency(u, other->id, UNIT_DEPENDENCY_FROM_PTR(dt));
|
||||
+ if (hashmap_remove(deps, other) && unit_should_warn_about_dependency(UNIT_DEPENDENCY_FROM_PTR(dt)))
|
||||
+ log_unit_warning(u, "Dependency %s=%s is dropped, as %s is merged into %s.",
|
||||
+ unit_dependency_to_string(UNIT_DEPENDENCY_FROM_PTR(dt)),
|
||||
+ other->id, other->id, u->id);
|
||||
|
||||
if (hashmap_isempty(deps))
|
||||
hashmap_free(hashmap_remove(u->dependencies, dt));
|
||||
@@ -1085,7 +1075,11 @@ static void unit_merge_dependencies(Unit *u, Unit *other) {
|
||||
if (back == u) {
|
||||
/* This is a dependency pointing back to the unit we want to merge with?
|
||||
* Suppress it (but warn) */
|
||||
- unit_maybe_warn_about_dependency(u, other->id, UNIT_DEPENDENCY_FROM_PTR(dt));
|
||||
+ if (unit_should_warn_about_dependency(UNIT_DEPENDENCY_FROM_PTR(dt)))
|
||||
+ log_unit_warning(u, "Dependency %s=%s in %s is dropped, as %s is merged into %s.",
|
||||
+ unit_dependency_to_string(UNIT_DEPENDENCY_FROM_PTR(dt)),
|
||||
+ u->id, other->id, other->id, u->id);
|
||||
+
|
||||
hashmap_remove(other_deps, back);
|
||||
continue;
|
||||
}
|
||||
@@ -3055,7 +3049,6 @@ int unit_add_dependency(
|
||||
[UNIT_IN_SLICE] = UNIT_SLICE_OF,
|
||||
[UNIT_SLICE_OF] = UNIT_IN_SLICE,
|
||||
};
|
||||
- Unit *original_u = u, *original_other = other;
|
||||
UnitDependencyAtom a;
|
||||
int r;
|
||||
|
||||
@@ -3074,7 +3067,9 @@ int unit_add_dependency(
|
||||
|
||||
/* We won't allow dependencies on ourselves. We will not consider them an error however. */
|
||||
if (u == other) {
|
||||
- unit_maybe_warn_about_dependency(original_u, original_other->id, d);
|
||||
+ if (unit_should_warn_about_dependency(d))
|
||||
+ log_unit_warning(u, "Dependency %s=%s is dropped.",
|
||||
+ unit_dependency_to_string(d), u->id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
From 53e0e6ef0eea396bb432cbfc1f2f6ea1272ff1f1 Mon Sep 17 00:00:00 2001
|
||||
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
||||
Date: Tue, 15 Nov 2022 23:08:35 +0900
|
||||
Subject: [PATCH] core/unit: fix logic of dropping self-referencing
|
||||
dependencies
|
||||
|
||||
Fixes a bug in 15ed3c3a188cf7fa5a60ae508fc7a3ed048d2220.
|
||||
---
|
||||
src/core/unit.c | 3 ++-
|
||||
1 file changed, 2 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/core/unit.c b/src/core/unit.c
|
||||
index 1a580157af..a9052428e4 100644
|
||||
--- a/src/core/unit.c
|
||||
+++ b/src/core/unit.c
|
||||
@@ -1131,10 +1131,11 @@ static void unit_merge_dependencies(Unit *u, Unit *other) {
|
||||
}
|
||||
} else {
|
||||
assert_se(r >= 0);
|
||||
- TAKE_PTR(other_deps);
|
||||
|
||||
if (hashmap_remove(other_deps, u))
|
||||
unit_maybe_warn_about_dependency(u, other->id, UNIT_DEPENDENCY_FROM_PTR(dt));
|
||||
+
|
||||
+ TAKE_PTR(other_deps);
|
||||
}
|
||||
}
|
||||
|
||||
--
|
||||
2.27.0
|
||||
|
||||
95
backport-core-unit-merge-two-loops-into-one.patch
Normal file
95
backport-core-unit-merge-two-loops-into-one.patch
Normal file
@ -0,0 +1,95 @@
|
||||
From 4b7918a65cc2571a2b3fc166229e1b8db463e217 Mon Sep 17 00:00:00 2001
|
||||
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
||||
Date: Thu, 17 Nov 2022 12:46:45 +0900
|
||||
Subject: [PATCH] core/unit: merge two loops into one
|
||||
|
||||
No functional change, just refactoring.
|
||||
---
|
||||
src/core/unit.c | 47 +++++++++++++++--------------------------------
|
||||
1 file changed, 15 insertions(+), 32 deletions(-)
|
||||
|
||||
diff --git a/src/core/unit.c b/src/core/unit.c
|
||||
index a9052428e4..0d52e4bf1a 100644
|
||||
--- a/src/core/unit.c
|
||||
+++ b/src/core/unit.c
|
||||
@@ -1048,7 +1048,6 @@ static void unit_merge_dependencies(Unit *u, Unit *other) {
|
||||
Hashmap *deps;
|
||||
void *dt; /* Actually of type UnitDependency, except that we don't bother casting it here,
|
||||
* since the hashmaps all want it as void pointer. */
|
||||
- int r;
|
||||
|
||||
assert(u);
|
||||
assert(other);
|
||||
@@ -1075,6 +1074,8 @@ static void unit_merge_dependencies(Unit *u, Unit *other) {
|
||||
if (!other_deps)
|
||||
break; /* done! */
|
||||
|
||||
+ deps = hashmap_get(u->dependencies, dt);
|
||||
+
|
||||
/* Now iterate through all dependencies of this dependency type, of 'other'. We refer to the
|
||||
* referenced units as 'back'. */
|
||||
HASHMAP_FOREACH_KEY(di_back.data, back, other_deps) {
|
||||
@@ -1085,6 +1086,7 @@ static void unit_merge_dependencies(Unit *u, Unit *other) {
|
||||
/* This is a dependency pointing back to the unit we want to merge with?
|
||||
* Suppress it (but warn) */
|
||||
unit_maybe_warn_about_dependency(u, other->id, UNIT_DEPENDENCY_FROM_PTR(dt));
|
||||
+ hashmap_remove(other_deps, back);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1103,40 +1105,21 @@ static void unit_merge_dependencies(Unit *u, Unit *other) {
|
||||
di_move.origin_mask,
|
||||
di_move.destination_mask) >= 0);
|
||||
}
|
||||
- }
|
||||
|
||||
- /* Now all references towards 'other' of the current type 'dt' are corrected to point to
|
||||
- * 'u'. Lets's now move the deps of type 'dt' from 'other' to 'u'. First, let's try to move
|
||||
- * them per type wholesale. */
|
||||
- r = hashmap_put(u->dependencies, dt, other_deps);
|
||||
- if (r == -EEXIST) {
|
||||
/* The target unit already has dependencies of this type, let's then merge this individually. */
|
||||
-
|
||||
- assert_se(deps = hashmap_get(u->dependencies, dt));
|
||||
-
|
||||
- for (;;) {
|
||||
- UnitDependencyInfo di_move;
|
||||
-
|
||||
- /* Get first dep */
|
||||
- di_move.data = hashmap_steal_first_key_and_value(other_deps, (void**) &back);
|
||||
- if (!di_move.data)
|
||||
- break; /* done */
|
||||
- if (back == u) {
|
||||
- /* Would point back to us, ignore */
|
||||
- unit_maybe_warn_about_dependency(u, other->id, UNIT_DEPENDENCY_FROM_PTR(dt));
|
||||
- continue;
|
||||
- }
|
||||
-
|
||||
- assert_se(unit_per_dependency_type_hashmap_update(deps, back, di_move.origin_mask, di_move.destination_mask) >= 0);
|
||||
- }
|
||||
- } else {
|
||||
- assert_se(r >= 0);
|
||||
-
|
||||
- if (hashmap_remove(other_deps, u))
|
||||
- unit_maybe_warn_about_dependency(u, other->id, UNIT_DEPENDENCY_FROM_PTR(dt));
|
||||
-
|
||||
- TAKE_PTR(other_deps);
|
||||
+ if (deps)
|
||||
+ assert_se(unit_per_dependency_type_hashmap_update(
|
||||
+ deps,
|
||||
+ back,
|
||||
+ di_back.origin_mask,
|
||||
+ di_back.destination_mask) >= 0);
|
||||
}
|
||||
+
|
||||
+ /* Now all references towards 'other' of the current type 'dt' are corrected to point to 'u'.
|
||||
+ * Lets's now move the deps of type 'dt' from 'other' to 'u'. If the unit does not have
|
||||
+ * dependencies of this type, let's move them per type wholesale. */
|
||||
+ if (!deps)
|
||||
+ assert_se(hashmap_put(u->dependencies, dt, TAKE_PTR(other_deps)) >= 0);
|
||||
}
|
||||
|
||||
other->dependencies = hashmap_free(other->dependencies);
|
||||
--
|
||||
2.27.0
|
||||
|
||||
44
backport-core-unit-merge-unit-names-after-merging-deps.patch
Normal file
44
backport-core-unit-merge-unit-names-after-merging-deps.patch
Normal file
@ -0,0 +1,44 @@
|
||||
From 1d0c81a05b1605a5fc3db44d5a157a1d6876eda9 Mon Sep 17 00:00:00 2001
|
||||
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
||||
Date: Wed, 16 Nov 2022 03:18:30 +0900
|
||||
Subject: [PATCH] core/unit: merge unit names after merging deps
|
||||
|
||||
Before:
|
||||
systemd[1]: issue-24990.service: Dependency Before=n/a dropped, merged into issue-24990.service
|
||||
After:
|
||||
systemd[1]: issue-24990.service: Dependency Before=test1.service dropped, merged into issue-24990.service
|
||||
---
|
||||
src/core/unit.c | 10 +++++-----
|
||||
1 file changed, 5 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/src/core/unit.c b/src/core/unit.c
|
||||
index 0d52e4bf1a..ea09416be5 100644
|
||||
--- a/src/core/unit.c
|
||||
+++ b/src/core/unit.c
|
||||
@@ -1165,11 +1165,6 @@ int unit_merge(Unit *u, Unit *other) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
- /* Merge names */
|
||||
- r = unit_merge_names(u, other);
|
||||
- if (r < 0)
|
||||
- return r;
|
||||
-
|
||||
/* Redirect all references */
|
||||
while (other->refs_by_target)
|
||||
unit_ref_set(other->refs_by_target, other->refs_by_target->source, u);
|
||||
@@ -1177,6 +1172,11 @@ int unit_merge(Unit *u, Unit *other) {
|
||||
/* Merge dependencies */
|
||||
unit_merge_dependencies(u, other);
|
||||
|
||||
+ /* Merge names. It is better to do that after merging deps, otherwise the log message contains n/a. */
|
||||
+ r = unit_merge_names(u, other);
|
||||
+ if (r < 0)
|
||||
+ return r;
|
||||
+
|
||||
other->load_state = UNIT_MERGED;
|
||||
other->merged_into = u;
|
||||
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -0,0 +1,36 @@
|
||||
From 28c5859fa30572950a24a7638a3a8191d65daf68 Mon Sep 17 00:00:00 2001
|
||||
From: licunlong <licunlong1@huawei.com>
|
||||
Date: Thu, 10 Mar 2022 09:22:29 +0800
|
||||
Subject: [PATCH] main: drop get_process_cmdline from crash handler
|
||||
get_process_cmdline calls malloc, which should be avoid in signal handler.
|
||||
|
||||
Fixes: #22690
|
||||
---
|
||||
src/core/main.c | 11 ++++++-----
|
||||
1 file changed, 6 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/src/core/main.c b/src/core/main.c
|
||||
index 41a4b4225f..7c9265f394 100644
|
||||
--- a/src/core/main.c
|
||||
+++ b/src/core/main.c
|
||||
@@ -274,11 +274,12 @@ _noreturn_ static void crash(int sig, siginfo_t *siginfo, void *context) {
|
||||
int r;
|
||||
|
||||
if (siginfo) {
|
||||
- _cleanup_free_ char *cmdline = NULL;
|
||||
- pid_t sender_pid = siginfo->si_pid;
|
||||
-
|
||||
- (void) get_process_cmdline(sender_pid, SIZE_MAX, 0, &cmdline);
|
||||
- log_emergency("Caught <%s> from PID "PID_FMT" (%s)", signal_to_string(sig), sender_pid, strna(cmdline));
|
||||
+ if (siginfo->si_pid == 0)
|
||||
+ log_emergency("Caught <%s> from unknown sender process.", signal_to_string(sig));
|
||||
+ else if (siginfo->si_pid == 1)
|
||||
+ log_emergency("Caught <%s> from our own process.", signal_to_string(sig));
|
||||
+ else
|
||||
+ log_emergency("Caught <%s> from PID "PID_FMT".", signal_to_string(sig), siginfo->si_pid);
|
||||
}
|
||||
|
||||
/* Order things nicely. */
|
||||
--
|
||||
2.27.0
|
||||
|
||||
54
backport-main-log-which-process-send-SIGNAL-to-PID1.patch
Normal file
54
backport-main-log-which-process-send-SIGNAL-to-PID1.patch
Normal file
@ -0,0 +1,54 @@
|
||||
From 7347b3db838ea3f02afc6c8a6dccac1ff8e7edbd Mon Sep 17 00:00:00 2001
|
||||
From: licunlong <licunlong1@huawei.com>
|
||||
Date: Tue, 8 Mar 2022 19:18:36 +0800
|
||||
Subject: [PATCH] main: log which process send SIGNAL to PID1 This can help
|
||||
users to figure out what makes systemd freeze. 1. Someone kills systemd
|
||||
accidentally, then the sender_pid won't be 1; 2. systemd triggers segfault or
|
||||
assert, then the sender_pid will be 1;
|
||||
|
||||
---
|
||||
src/core/main.c | 14 +++++++++++---
|
||||
1 file changed, 11 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/src/core/main.c b/src/core/main.c
|
||||
index 5009b8d85f..41a4b4225f 100644
|
||||
--- a/src/core/main.c
|
||||
+++ b/src/core/main.c
|
||||
@@ -228,7 +228,7 @@ _noreturn_ static void freeze_or_exit_or_reboot(void) {
|
||||
freeze();
|
||||
}
|
||||
|
||||
-_noreturn_ static void crash(int sig) {
|
||||
+_noreturn_ static void crash(int sig, siginfo_t *siginfo, void *context) {
|
||||
struct sigaction sa;
|
||||
pid_t pid;
|
||||
|
||||
@@ -273,6 +273,14 @@ _noreturn_ static void crash(int sig) {
|
||||
siginfo_t status;
|
||||
int r;
|
||||
|
||||
+ if (siginfo) {
|
||||
+ _cleanup_free_ char *cmdline = NULL;
|
||||
+ pid_t sender_pid = siginfo->si_pid;
|
||||
+
|
||||
+ (void) get_process_cmdline(sender_pid, SIZE_MAX, 0, &cmdline);
|
||||
+ log_emergency("Caught <%s> from PID "PID_FMT" (%s)", signal_to_string(sig), sender_pid, strna(cmdline));
|
||||
+ }
|
||||
+
|
||||
/* Order things nicely. */
|
||||
r = wait_for_terminate(pid, &status);
|
||||
if (r < 0)
|
||||
@@ -330,8 +338,8 @@ _noreturn_ static void crash(int sig) {
|
||||
|
||||
static void install_crash_handler(void) {
|
||||
static const struct sigaction sa = {
|
||||
- .sa_handler = crash,
|
||||
- .sa_flags = SA_NODEFER, /* So that we can raise the signal again from the signal handler */
|
||||
+ .sa_sigaction = crash,
|
||||
+ .sa_flags = SA_NODEFER | SA_SIGINFO, /* So that we can raise the signal again from the signal handler */
|
||||
};
|
||||
int r;
|
||||
|
||||
--
|
||||
2.27.0
|
||||
|
||||
40
backport-pid1-fix-segv-triggered-by-status-query.patch
Normal file
40
backport-pid1-fix-segv-triggered-by-status-query.patch
Normal file
@ -0,0 +1,40 @@
|
||||
From 0aadfe4937045efd5a7a53a176d05db7dc937435 Mon Sep 17 00:00:00 2001
|
||||
From: Robin Humble <plaguedbypenguins@gmail.com>
|
||||
Date: Wed, 1 Feb 2023 23:36:48 +1100
|
||||
Subject: [PATCH] pid1: fix segv triggered by status query (#26279)
|
||||
|
||||
If any query makes it to the end of install_info_follow() then I think symlink_target is set to NULL.
|
||||
If that is followed by -EXDEV from unit_file_load_or_readlink(), then that causes basename(NULL)
|
||||
which segfaults pid 1.
|
||||
|
||||
This is triggered by eg. "systemctl status crond" in RHEL9 if
|
||||
|
||||
/etc/systemd/system/crond.service
|
||||
-> /ram/etc/systemd/system/crond.service
|
||||
-> /usr/lib/systemd/system/.crond.service.blah.blah
|
||||
-> /usr/lib/systemd/system/crond.service
|
||||
|
||||
(cherry picked from commit 19cfda9fc3c60de21a362ebb56bcb9f4a9855e85)
|
||||
(cherry picked from commit 015b0ca9286471c05fe88cfa277dd82e20537ba8)
|
||||
(cherry picked from commit 9a906fae890904284fe91e29b6bdcb64429fecba)
|
||||
(cherry picked from commit a2dc9e3be9a8895edcba10f4c0d8d703b435c18b)
|
||||
---
|
||||
src/shared/install.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/shared/install.c b/src/shared/install.c
|
||||
index 4bf868f8e9..f038665dea 100644
|
||||
--- a/src/shared/install.c
|
||||
+++ b/src/shared/install.c
|
||||
@@ -1609,7 +1609,7 @@ static int install_info_traverse(
|
||||
}
|
||||
|
||||
r = install_info_follow(c, i, paths->root_dir, flags, false);
|
||||
- if (r == -EXDEV) {
|
||||
+ if (r == -EXDEV && i->symlink_target) {
|
||||
_cleanup_free_ char *buffer = NULL;
|
||||
const char *bn;
|
||||
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -0,0 +1,210 @@
|
||||
From 5f882cc3ab32636d9242effb2cefad20d92d2ec2 Mon Sep 17 00:00:00 2001
|
||||
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
||||
Date: Tue, 15 Nov 2022 21:52:19 +0900
|
||||
Subject: [PATCH] test: add test case for sysv-generator and invalid dependency
|
||||
|
||||
---
|
||||
test/units/assert.sh | 58 +++++++++++++++++++
|
||||
test/units/testsuite-26.sh | 116 ++++++++++++++++++++++++++++++++++++-
|
||||
2 files changed, 172 insertions(+), 2 deletions(-)
|
||||
create mode 100755 test/units/assert.sh
|
||||
|
||||
diff --git a/test/units/assert.sh b/test/units/assert.sh
|
||||
new file mode 100755
|
||||
index 0000000..2f4d93a
|
||||
--- /dev/null
|
||||
+++ b/test/units/assert.sh
|
||||
@@ -0,0 +1,58 @@
|
||||
+#!/usr/bin/env bash
|
||||
+# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
+
|
||||
+# utility functions for shell tests
|
||||
+
|
||||
+assert_true() {(
|
||||
+ set +ex
|
||||
+
|
||||
+ local rc
|
||||
+
|
||||
+ "$@"
|
||||
+ rc=$?
|
||||
+ if [[ $rc -ne 0 ]]; then
|
||||
+ echo "FAIL: command '$*' failed with exit code $rc" >&2
|
||||
+ exit 1
|
||||
+ fi
|
||||
+)}
|
||||
+
|
||||
+
|
||||
+assert_eq() {(
|
||||
+ set +ex
|
||||
+
|
||||
+ if [[ "${1?}" != "${2?}" ]]; then
|
||||
+ echo "FAIL: expected: '$2' actual: '$1'" >&2
|
||||
+ exit 1
|
||||
+ fi
|
||||
+)}
|
||||
+
|
||||
+assert_in() {(
|
||||
+ set +ex
|
||||
+
|
||||
+ if ! [[ "${2?}" =~ ${1?} ]]; then
|
||||
+ echo "FAIL: '$1' not found in:" >&2
|
||||
+ echo "$2" >&2
|
||||
+ exit 1
|
||||
+ fi
|
||||
+)}
|
||||
+
|
||||
+assert_not_in() {(
|
||||
+ set +ex
|
||||
+
|
||||
+ if [[ "${2?}" =~ ${1?} ]]; then
|
||||
+ echo "FAIL: '$1' found in:" >&2
|
||||
+ echo "$2" >&2
|
||||
+ exit 1
|
||||
+ fi
|
||||
+)}
|
||||
+
|
||||
+assert_rc() {(
|
||||
+ set +ex
|
||||
+
|
||||
+ local rc exp="${1?}"
|
||||
+
|
||||
+ shift
|
||||
+ "$@"
|
||||
+ rc=$?
|
||||
+ assert_eq "$rc" "$exp"
|
||||
+)}
|
||||
diff --git a/test/units/testsuite-26.sh b/test/units/testsuite-26.sh
|
||||
index 7982099..fe6b63b 100755
|
||||
--- a/test/units/testsuite-26.sh
|
||||
+++ b/test/units/testsuite-26.sh
|
||||
@@ -2,6 +2,11 @@
|
||||
set -eux
|
||||
set -o pipefail
|
||||
|
||||
+# shellcheck source=test/units/assert.sh
|
||||
+. "$(dirname "$0")"/assert.sh
|
||||
+
|
||||
+: >/failed
|
||||
+
|
||||
# Make sure PATH is set
|
||||
systemctl show-environment | grep -q '^PATH='
|
||||
|
||||
@@ -26,6 +31,113 @@ systemctl show-environment | grep '^FOO=$' && exit 1
|
||||
systemctl show-environment | grep '^PATH=.*testaddition$' && exit 1
|
||||
systemctl show-environment | grep -q '^PATH='
|
||||
|
||||
-echo OK >/testok
|
||||
+# test for sysv-generator (issue #24990)
|
||||
+if [[ -x /usr/lib/systemd/system-generators/systemd-sysv-generator ]]; then
|
||||
+ # This is configurable via -Dsysvinit-path=, but we can't get the value
|
||||
+ # at runtime, so let's just support the two most common paths for now.
|
||||
+ [[ -d /etc/rc.d/init.d ]] && SYSVINIT_PATH="/etc/rc.d/init.d" || SYSVINIT_PATH="/etc/init.d"
|
||||
+
|
||||
+ # invalid dependency
|
||||
+ cat >"${SYSVINIT_PATH:?}/issue-24990" <<\EOF
|
||||
+#!/bin/bash
|
||||
+
|
||||
+### BEGIN INIT INFO
|
||||
+# Provides:test1 test2
|
||||
+# Required-Start:test1 $remote_fs $network
|
||||
+# Required-Stop:test1 $remote_fs $network
|
||||
+# Description:Test
|
||||
+# Short-Description: Test
|
||||
+### END INIT INFO
|
||||
+
|
||||
+case "$1" in
|
||||
+ start)
|
||||
+ echo "Starting issue-24990.service"
|
||||
+ sleep 1000 &
|
||||
+ ;;
|
||||
+ stop)
|
||||
+ echo "Stopping issue-24990.service"
|
||||
+ sleep 10 &
|
||||
+ ;;
|
||||
+ *)
|
||||
+ echo "Usage: service test {start|stop|restart|status}"
|
||||
+ ;;
|
||||
+esac
|
||||
+EOF
|
||||
+
|
||||
+ chmod +x "$SYSVINIT_PATH/issue-24990"
|
||||
+ systemctl daemon-reload
|
||||
+ [[ -L /run/systemd/generator.late/test1.service ]]
|
||||
+ [[ -L /run/systemd/generator.late/test2.service ]]
|
||||
+ assert_eq "$(readlink -f /run/systemd/generator.late/test1.service)" "/run/systemd/generator.late/issue-24990.service"
|
||||
+ assert_eq "$(readlink -f /run/systemd/generator.late/test2.service)" "/run/systemd/generator.late/issue-24990.service"
|
||||
+ output=$(systemctl cat issue-24990)
|
||||
+ assert_in "SourcePath=$SYSVINIT_PATH/issue-24990" "$output"
|
||||
+ assert_in "Description=LSB: Test" "$output"
|
||||
+ assert_in "After=test1.service" "$output"
|
||||
+ assert_in "After=remote-fs.target" "$output"
|
||||
+ assert_in "After=network-online.target" "$output"
|
||||
+ assert_in "Wants=network-online.target" "$output"
|
||||
+ assert_in "ExecStart=$SYSVINIT_PATH/issue-24990 start" "$output"
|
||||
+ assert_in "ExecStop=$SYSVINIT_PATH/issue-24990 stop" "$output"
|
||||
+ systemctl status issue-24990 || :
|
||||
+ systemctl show issue-24990
|
||||
+ assert_not_in "issue-24990.service" "$(systemctl show --property=After --value)"
|
||||
+ assert_not_in "issue-24990.service" "$(systemctl show --property=Before --value)"
|
||||
+
|
||||
+ if ! systemctl is-active network-online.target; then
|
||||
+ systemctl start network-online.target
|
||||
+ fi
|
||||
+
|
||||
+ systemctl restart issue-24990
|
||||
+ systemctl stop issue-24990
|
||||
+
|
||||
+ # valid dependency
|
||||
+ cat >"$SYSVINIT_PATH/issue-24990" <<\EOF
|
||||
+#!/bin/bash
|
||||
+
|
||||
+### BEGIN INIT INFO
|
||||
+# Provides:test1 test2
|
||||
+# Required-Start:$remote_fs
|
||||
+# Required-Stop:$remote_fs
|
||||
+# Description:Test
|
||||
+# Short-Description: Test
|
||||
+### END INIT INFO
|
||||
+
|
||||
+case "$1" in
|
||||
+ start)
|
||||
+ echo "Starting issue-24990.service"
|
||||
+ sleep 1000 &
|
||||
+ ;;
|
||||
+ stop)
|
||||
+ echo "Stopping issue-24990.service"
|
||||
+ sleep 10 &
|
||||
+ ;;
|
||||
+ *)
|
||||
+ echo "Usage: service test {start|stop|restart|status}"
|
||||
+ ;;
|
||||
+esac
|
||||
+EOF
|
||||
+
|
||||
+ chmod +x "$SYSVINIT_PATH/issue-24990"
|
||||
+ systemctl daemon-reload
|
||||
+ [[ -L /run/systemd/generator.late/test1.service ]]
|
||||
+ [[ -L /run/systemd/generator.late/test2.service ]]
|
||||
+ assert_eq "$(readlink -f /run/systemd/generator.late/test1.service)" "/run/systemd/generator.late/issue-24990.service"
|
||||
+ assert_eq "$(readlink -f /run/systemd/generator.late/test2.service)" "/run/systemd/generator.late/issue-24990.service"
|
||||
+ output=$(systemctl cat issue-24990)
|
||||
+ assert_in "SourcePath=$SYSVINIT_PATH/issue-24990" "$output"
|
||||
+ assert_in "Description=LSB: Test" "$output"
|
||||
+ assert_in "After=remote-fs.target" "$output"
|
||||
+ assert_in "ExecStart=$SYSVINIT_PATH/issue-24990 start" "$output"
|
||||
+ assert_in "ExecStop=$SYSVINIT_PATH/issue-24990 stop" "$output"
|
||||
+ systemctl status issue-24990 || :
|
||||
+ systemctl show issue-24990
|
||||
+ assert_not_in "issue-24990.service" "$(systemctl show --property=After --value)"
|
||||
+ assert_not_in "issue-24990.service" "$(systemctl show --property=Before --value)"
|
||||
+
|
||||
+ systemctl restart issue-24990
|
||||
+ systemctl stop issue-24990
|
||||
+fi
|
||||
|
||||
-exit 0
|
||||
+touch /testok
|
||||
+rm /failed
|
||||
--
|
||||
2.27.0
|
||||
|
||||
15
systemd.spec
15
systemd.spec
@ -21,7 +21,7 @@
|
||||
Name: systemd
|
||||
Url: https://www.freedesktop.org/wiki/Software/systemd
|
||||
Version: 249
|
||||
Release: 48
|
||||
Release: 49
|
||||
License: MIT and LGPLv2+ and GPLv2+
|
||||
Summary: System and Service Manager
|
||||
|
||||
@ -441,6 +441,16 @@ Patch6393: backport-analyze-add-forgotten-return-statement.patch
|
||||
Patch6394: backport-shared-condition-avoid-nss-lookup-in-PID1.patch
|
||||
Patch6395: backport-logind-fix-getting-property-OnExternalPower-via-D-Bu.patch
|
||||
Patch6396: backport-udev-support-by-path-devlink-for-multipath-nvme-bloc.patch
|
||||
Patch6397: backport-argv-util-also-update-program_invocation_short_name.patch
|
||||
Patch6398: backport-pid1-fix-segv-triggered-by-status-query.patch
|
||||
Patch6399: backport-main-log-which-process-send-SIGNAL-to-PID1.patch
|
||||
Patch6400: backport-main-drop-get_process_cmdline-from-crash-handler.patch
|
||||
Patch6401: backport-core-unit-drop-dependency-to-the-unit-being-merged.patch
|
||||
Patch6402: backport-core-unit-fix-logic-of-dropping-self-referencing-dep.patch
|
||||
Patch6403: backport-core-unit-merge-two-loops-into-one.patch
|
||||
Patch6404: backport-core-unit-merge-unit-names-after-merging-deps.patch
|
||||
Patch6405: backport-core-unit-fix-log-message.patch
|
||||
Patch6406: backport-test-add-test-case-for-sysv-generator-and-invalid-de.patch
|
||||
|
||||
Patch9001: update-rtc-with-system-clock-when-shutdown.patch
|
||||
Patch9002: udev-add-actions-while-rename-netif-failed.patch
|
||||
@ -1911,6 +1921,9 @@ fi
|
||||
%{_libdir}/security/pam_systemd.so
|
||||
|
||||
%changelog
|
||||
* Wed Mar 22 2023 hongjinghao <hongjinghao@huawei.comg> - 249-49
|
||||
- backport: sync patches from systemd community
|
||||
|
||||
* Tue Mar 7 2023 wangyuhang <wangyuhang27@huawei.com> -249-48
|
||||
- fix symlinks to NVMe drives are missing in /dev/disk/by-path
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user