1 Star 0 Fork 50

zyu_cheng/systemd

forked from src-anolis-os/systemd 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
10004-Do-not-go-into-freeze-when-systemd-crashd.patch 3.11 KB
一键复制 编辑 原始数据 按行查看 历史
庞庆 提交于 2022-04-19 15:08 . Add optimized patches
From 64072aab92ff6489a2e460a9bdd1cfefa587264b Mon Sep 17 00:00:00 2001
From: Yuanhong Peng <yummypeng@linux.alibaba.com>
Date: Tue, 19 Apr 2022 13:36:09 +0800
Subject: [PATCH] Do not go into freeze when systemd crashd
---
src/core/main.c | 41 ++++++++++++++++++++++++++++++++++++++++-
1 file changed, 40 insertions(+), 1 deletion(-)
diff --git a/src/core/main.c b/src/core/main.c
index 0aec5d1..db91151 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -3,6 +3,7 @@
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
+#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
@@ -10,6 +11,7 @@
#include <sys/prctl.h>
#include <sys/reboot.h>
#include <sys/stat.h>
+#include <sys/wait.h>
#include <unistd.h>
#if HAVE_SECCOMP
#include <seccomp.h>
@@ -135,10 +137,41 @@ static sd_id128_t arg_machine_id;
static EmergencyAction arg_cad_burst_action;
static CPUSet arg_cpu_affinity;
static NUMAPolicy arg_numa_policy;
+static bool reexec_jmp_can = false;
+static bool reexec_jmp_inited = false;
+static sigjmp_buf reexec_jmp_buf;
static int parse_configuration(const struct rlimit *saved_rlimit_nofile,
const struct rlimit *saved_rlimit_memlock);
+static void reexec_handler(int sig) {
+ reexec_jmp_can = true;
+}
+
+_noreturn_ static void freeze_wait_upgrade(void) {
+ struct sigaction sa;
+ sigset_t ss;
+
+ sigemptyset(&ss);
+ sigaddset(&ss, SIGTERM);
+ sigprocmask(SIG_UNBLOCK, &ss, NULL);
+
+ sa.sa_handler = reexec_handler;
+ sa.sa_flags = SA_RESTART;
+ sigaction(SIGTERM, &sa, NULL);
+
+ log_error("freeze_wait_upgrade: %d\n", reexec_jmp_inited);
+ reexec_jmp_can = false;
+ while(1) {
+ usleep(10000);
+ if (reexec_jmp_inited && reexec_jmp_can) {
+ log_error("goto manager_reexecute.\n");
+ siglongjmp(reexec_jmp_buf, 1);
+ }
+ waitpid(-1, NULL, WNOHANG);
+ }
+}
+
_noreturn_ static void freeze_or_exit_or_reboot(void) {
/* If we are running in a contianer, let's prefer exiting, after all we can propagate an exit code to the
* container manager, and thus inform it that something went wrong. */
@@ -157,7 +190,8 @@ _noreturn_ static void freeze_or_exit_or_reboot(void) {
}
log_emergency("Freezing execution.");
- freeze();
+ freeze_wait_upgrade();
+
}
_noreturn_ static void crash(int sig) {
@@ -1667,6 +1701,10 @@ static int invoke_main_loop(
assert(ret_switch_root_init);
assert(ret_error_message);
+ reexec_jmp_inited = true;
+ if (sigsetjmp(reexec_jmp_buf, 1))
+ goto manager_reexecute;
+
for (;;) {
r = manager_loop(m);
if (r < 0) {
@@ -1709,6 +1747,7 @@ static int invoke_main_loop(
case MANAGER_REEXECUTE:
+manager_reexecute:
r = prepare_reexecute(m, &arg_serialization, ret_fds, false);
if (r < 0) {
*ret_error_message = "Failed to prepare for reexecution";
--
2.27.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zyu_cheng/systemd.git
git@gitee.com:zyu_cheng/systemd.git
zyu_cheng
systemd
systemd
a8

搜索帮助