1 Star 0 Fork 98

huajingyun/systemd_1

forked from src-openEuler/systemd 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
shutdown-reboot-when-recieve-crash-signal.patch 2.31 KB
一键复制 编辑 原始数据 按行查看 历史
胡宇彪 提交于 2023-07-31 10:00 . sync the patch from v249
From 3ac4d1fc1a067afc0e0d4ca37a44ac252ee8b96b Mon Sep 17 00:00:00 2001
From: xujing <[email protected]>
Date: Tue, 8 Feb 2022 21:02:31 +0800
Subject: [PATCH] shutdown: reboot when recieve crash signal
---
src/shutdown/shutdown.c | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/src/shutdown/shutdown.c b/src/shutdown/shutdown.c
index 1bbabfb..8f68559 100644
--- a/src/shutdown/shutdown.c
+++ b/src/shutdown/shutdown.c
@@ -322,6 +322,26 @@ static void bump_sysctl_printk_log_level(int min_level) {
log_debug_errno(r, "Failed to bump kernel.printk to %i: %m", min_level + 1);
}
+_noreturn_ static void crash(int sig) {
+ if (getpid_cached() != 1)
+ /* Pass this on immediately, if this is not PID 1 */
+ (void) raise(sig);
+ else {
+ bool in_container = detect_container() > 0;
+
+ log_info("Recieve signal %d.", sig);
+
+ broadcast_signal(SIGTERM, true, true, arg_timeout);
+ broadcast_signal(SIGKILL, true, false, arg_timeout);
+
+ if (!in_container)
+ sync_with_progress();
+
+ log_info("Rebooting now.");
+ (void) reboot(RB_AUTOBOOT);
+ }
+}
+
static void init_watchdog(void) {
const char *s;
int r;
@@ -356,6 +376,19 @@ int main(int argc, char *argv[]) {
usec_t now_time, time_interval;
pid_t pid;
bool fork_failed = false;
+ static const struct sigaction sa = {
+ .sa_handler = crash,
+ .sa_flags = SA_NODEFER, /* So that we can raise the signal again from the signal handler */
+ };
+
+ (void) reset_all_signal_handlers();
+ (void) ignore_signals(SIGNALS_IGNORE, -1);
+
+ /* We ignore the return value here, since, we don't mind if we
+ * cannot set up a crash handler */
+ r = sigaction_many(&sa, SIGNALS_CRASH_HANDLER, -1);
+ if (r < 0)
+ log_debug_errno(r, "I had trouble setting up the crash handler, ignoring: %m");
/* The log target defaults to console, but the original systemd process will pass its log target in through a
* command line argument, which will override this default. Also, ensure we'll never log to the journal or
--
2.33.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/huajingyun/systemd_1.git
[email protected]:huajingyun/systemd_1.git
huajingyun
systemd_1
systemd_1
master

搜索帮助