From edff70d9189cb5a86c066669318fa44c2362626d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=80=84=E5=87=AF=E8=90=8C00355110?= Date: Wed, 15 Oct 2025 10:47:40 +0800 Subject: [PATCH] print-backtrack-log-to-var-log-messages --- ...nt-backtrack-log-to-var-log-messages.patch | 438 ++++++++++++++++++ systemd.spec | 8 +- 2 files changed, 444 insertions(+), 2 deletions(-) create mode 100644 0497-print-backtrack-log-to-var-log-messages.patch diff --git a/0497-print-backtrack-log-to-var-log-messages.patch b/0497-print-backtrack-log-to-var-log-messages.patch new file mode 100644 index 0000000..f57f201 --- /dev/null +++ b/0497-print-backtrack-log-to-var-log-messages.patch @@ -0,0 +1,438 @@ +From f9400249b76769369c1239ed08ddf3da4ce7eebf Mon Sep 17 00:00:00 2001 +From: ε”δΈœζ˜Ÿ +Date: Tue, 25 Feb 2025 20:20:11 +0800 +Subject: [PATCH] print backtrack log to /var/log/messages + before reboot +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +--- + src/basic/check-filesystems.sh | 2 +- + src/journal/journald.conf | 2 +- + src/systemctl/backtrack.c | 168 ++++++++++++++++++++++ + src/systemctl/backtrack.h | 8 ++ + src/systemctl/meson.build | 1 + + src/systemctl/systemctl-compat-halt.c | 9 +- + src/systemctl/systemctl-compat-shutdown.c | 8 +- + src/systemctl/systemctl-compat-telinit.c | 5 + + src/systemctl/systemctl-start-special.c | 10 +- + 8 files changed, 205 insertions(+), 6 deletions(-) + create mode 100644 src/systemctl/backtrack.c + create mode 100644 src/systemctl/backtrack.h + +diff --git a/src/basic/check-filesystems.sh b/src/basic/check-filesystems.sh +index 696ef61..f0e1d2a 100644 +--- a/src/basic/check-filesystems.sh ++++ b/src/basic/check-filesystems.sh +@@ -23,7 +23,7 @@ + # STACK_END_MAGIC doesn't refer to a filesystem + # mtd_inode was removed in 2015 + # futexfs was removed in 2018 +- if [[ "$fs" =~ ^(STACK_END_MAGIC|MTD_INODE_FS_MAGIC|FUTEXFS_SUPER_MAGIC)$ ]]; then ++ if [[ "$fs" =~ ^(STACK_END_MAGIC|MTD_INODE_FS_MAGIC|FUTEXFS_SUPER_MAGIC|GROUP_BALANCER_MAGIC)$ ]]; then + continue + fi + echo "Filesystem found in kernel header but not in $(basename "$filesystems_gperf"): $fs"; +diff --git a/src/journal/journald.conf b/src/journal/journald.conf +index 7b9e232..7c7c577 100644 +--- a/src/journal/journald.conf ++++ b/src/journal/journald.conf +@@ -17,7 +17,7 @@ + # See journald.conf(5) for details. + + [Journal] +-#Storage=auto ++Storage=persistent + #Compress=yes + #Seal=yes + #SplitMode=uid +diff --git a/src/systemctl/backtrack.c b/src/systemctl/backtrack.c +new file mode 100644 +index 0000000..7b83347 +--- /dev/null ++++ b/src/systemctl/backtrack.c +@@ -0,0 +1,168 @@ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include "backtrack.h" ++#include "process-util.h" ++#include "string-util.h" ++#include "log.h" ++ ++ ++ ++#define STRIPBLANK(s, p, len) \ ++ do \ ++{\ ++ (p) = (s)+(len)-1; \ ++ while ( *(p) == '\n' && (p) >= (s) ) { \ ++ *(p) = '\0'; \ ++ (p)--; \ ++ } \ ++ (p) = (s); \ ++ while( (*(p) == '\t' || *(p) == ' ')&& *(p) != '\n' ) \ ++ (p)++; \ ++}while(0) ++ ++ ++static void buf_format(char * buf, const int size, int * offset, const char * fmt, ...) ++{ ++ int free_size = 0; ++ int ret; ++ va_list args; ++ ++ if (NULL != buf && 0 <= (*offset) && (*offset) <= size){ ++ free_size = size - (*offset); ++ va_start(args, fmt); ++ ret = vsnprintf(buf + (*offset), free_size, fmt, args); ++ if (ret < free_size){ ++ *offset += ret; ++ } else { ++ *offset = size; ++ } ++ va_end(args); ++ } ++} ++ ++static void get_process_info(char *pid , char* buf, int size, int times) ++{ ++ FILE *fp; ++ char *p; ++ char name[32]={'\0'}; ++ char ppid[12]={'\0'}; ++ char line[100]={'\0'}; ++ int offset = 0; ++ ++ if(pid == NULL || buf == NULL){ ++ syslog(LOG_WARNING, "%s, %s, input parameteter is invalid.", ++ __FILE__, __func__); ++ return; ++ } ++ ++ if (size <= 1 || (++times >= 16 )) ++ return; ++ snprintf(name, sizeof(name),"/proc/%s/cmdline" , pid); ++ if (NULL == (fp = fopen(name, "r")) ){ ++ syslog(LOG_WARNING, "open file %s failed, %d (%s)", ++ name, errno, strerror(errno)); ++ return; ++ } ++ if (fgets(line, sizeof(line), fp)){ ++ buf_format(buf, size, &offset, "[%s", line); ++ } ++ fclose(fp); ++ ++ snprintf(name, sizeof(name), "/proc/%s/status", pid); ++ if (NULL == (fp = fopen(name, "r")) ){ ++ syslog(LOG_WARNING, "open file %s failed, %d (%s)", ++ name, errno, strerror(errno)); ++ return; ++ } ++ while(fgets(line , sizeof(line), fp)){ ++ if (offset == 0 && strncmp(line , "Name:", 5) == 0){ ++ STRIPBLANK(line+5 , p , strlen(line+5)); ++ buf_format(buf, size, &offset, "[%s", p); ++ continue; ++ } ++ /* receive ppid.*/ ++ if(strncmp(line , "PPid:", 5) == 0){ ++ STRIPBLANK(line+5 , p , strlen(line+5)); ++ snprintf(ppid, sizeof(ppid),"%s",p); ++ break; ++ } ++ } ++ buf_format(buf, size, &offset, " %s]", pid); ++ fclose(fp); ++ ++ if (!strcmp(ppid, pid) || !strcmp(pid, "0") || !strcmp(pid, "1")) ++ return; ++ get_process_info(ppid, buf + offset, size - offset, times); ++ return; ++} ++ ++#define BT_BUF_SIZE 4096 ++#define RB_PREFIX_NAME "[reboot backtrack]" ++void backtrack(const char* msg) ++{ ++ char * buf; ++ char pid[12]={'\0'}; ++ int times = 0; ++ ++ buf = malloc(BT_BUF_SIZE); ++ if(buf == NULL){ ++ syslog(LOG_NOTICE, "can not alloc buf memory, %s(%s).", ++ __FILE__, __func__); ++ return; ++ } ++ ++ memset(buf, 0, BT_BUF_SIZE); ++ if(msg != NULL) ++ syslog(LOG_NOTICE, "%s", msg); ++ snprintf(pid, sizeof(pid), "%d", getpid()); ++ get_process_info(pid, buf, BT_BUF_SIZE - 1, times); ++ syslog(LOG_NOTICE, "%s: %s", RB_PREFIX_NAME, buf); ++ free(buf); ++ return; ++} ++ ++void backtrack_special(enum action a) ++{ ++ switch (a) { ++ case ACTION_HALT: ++ backtrack("backtrack: call systemctl halt."); ++ break; ++ ++ case ACTION_POWEROFF: ++ backtrack("backtrack: call systemctl poweroff."); ++ break; ++ ++ case ACTION_REBOOT: ++ backtrack("backtrack: call systemctl reboot."); ++ break; ++ ++ default: ++ break; ++ } ++} ++ ++void backtrack_sysv(void) ++{ ++ char *cmdline=NULL; ++ char *msg = NULL; ++ ++ if (pid_get_cmdline(getpid(), SIZE_MAX, 0, &cmdline) >= 0) { ++ msg = strjoina("backtrack: call ", cmdline); ++ free(cmdline); ++ } ++ ++ if(msg == NULL) ++ log_warning("Failed to get cmdline of program(%s)", program_invocation_short_name); ++ else ++ backtrack(msg); ++ ++} +\ No newline at end of file +diff --git a/src/systemctl/backtrack.h b/src/systemctl/backtrack.h +new file mode 100644 +index 0000000..d580057 +--- /dev/null ++++ b/src/systemctl/backtrack.h +@@ -0,0 +1,8 @@ ++#pragma once ++#include "systemctl.h" ++ ++void backtrack(const char* msg); ++ ++void backtrack_special(enum action a); ++ ++void backtrack_sysv(void); +\ No newline at end of file +diff --git a/src/systemctl/meson.build b/src/systemctl/meson.build +index 255c639..3330fca 100644 +--- a/src/systemctl/meson.build ++++ b/src/systemctl/meson.build +@@ -38,6 +38,7 @@ systemctl_sources = files( + 'systemctl-util.c', + 'systemctl-whoami.c', + 'systemctl.c', ++ 'backtrack.c', + ) + + if get_option('link-systemctl-shared') +diff --git a/src/systemctl/systemctl-compat-halt.c b/src/systemctl/systemctl-compat-halt.c +index 4f6e304..b218f6e 100644 +--- a/src/systemctl/systemctl-compat-halt.c ++++ b/src/systemctl/systemctl-compat-halt.c +@@ -17,6 +17,7 @@ + #include "systemctl.h" + #include "terminal-util.h" + #include "utmp-wtmp.h" ++#include "backtrack.h" + + static int halt_help(void) { + _cleanup_free_ char *link = NULL; +@@ -87,7 +88,8 @@ int halt_parse_argv(int argc, char *argv[]) { + if (utmp_get_runlevel(&runlevel, NULL) >= 0) + if (IN_SET(runlevel, '0', '6')) + arg_force = 2; +- ++ if(argc == 1) ++ backtrack_sysv(); + while ((c = getopt_long(argc, argv, "pfwdnih", options, NULL)) >= 0) + switch (c) { + +@@ -96,19 +98,23 @@ int halt_parse_argv(int argc, char *argv[]) { + + case ARG_HALT: + arg_action = ACTION_HALT; ++ backtrack_sysv(); + break; + + case 'p': + if (arg_action != ACTION_REBOOT) + arg_action = ACTION_POWEROFF; ++ backtrack_sysv(); + break; + + case ARG_REBOOT: + arg_action = ACTION_REBOOT; ++ backtrack_sysv(); + break; + + case 'f': + arg_force = 2; ++ backtrack_sysv(); + break; + + case 'w': +@@ -117,6 +123,7 @@ int halt_parse_argv(int argc, char *argv[]) { + + case 'd': + arg_no_wtmp = true; ++ backtrack_sysv(); + break; + + case 'n': +diff --git a/src/systemctl/systemctl-compat-shutdown.c b/src/systemctl/systemctl-compat-shutdown.c +index 881d00e..9f7eba7 100644 +--- a/src/systemctl/systemctl-compat-shutdown.c ++++ b/src/systemctl/systemctl-compat-shutdown.c +@@ -9,6 +9,7 @@ + #include "systemctl-sysv-compat.h" + #include "systemctl.h" + #include "terminal-util.h" ++#include "backtrack.h" + + static int shutdown_help(void) { + _cleanup_free_ char *link = NULL; +@@ -69,7 +70,8 @@ int shutdown_parse_argv(int argc, char *argv[]) { + + assert(argc >= 0); + assert(argv); +- ++ if(argc == 1) ++ backtrack_sysv(); + while ((c = getopt_long(argc, argv, "HPrhkKat:fFc", options, NULL)) >= 0) + switch (c) { + +@@ -78,10 +80,12 @@ int shutdown_parse_argv(int argc, char *argv[]) { + + case 'H': + arg_action = ACTION_HALT; ++ backtrack_sysv(); + break; + + case 'P': + arg_action = ACTION_POWEROFF; ++ backtrack_sysv(); + break; + + case 'r': +@@ -89,6 +93,7 @@ int shutdown_parse_argv(int argc, char *argv[]) { + arg_action = ACTION_KEXEC; + else + arg_action = ACTION_REBOOT; ++ backtrack_sysv(); + break; + + case 'K': +@@ -98,6 +103,7 @@ int shutdown_parse_argv(int argc, char *argv[]) { + case 'h': + if (arg_action != ACTION_HALT) + arg_action = ACTION_POWEROFF; ++ backtrack_sysv(); + break; + + case 'k': +diff --git a/src/systemctl/systemctl-compat-telinit.c b/src/systemctl/systemctl-compat-telinit.c +index 20325e5..db75f90 100644 +--- a/src/systemctl/systemctl-compat-telinit.c ++++ b/src/systemctl/systemctl-compat-telinit.c +@@ -12,6 +12,7 @@ + #include "systemctl-sysv-compat.h" + #include "systemctl.h" + #include "terminal-util.h" ++#include "backtrack.h" + + static int telinit_help(void) { + _cleanup_free_ char *link = NULL; +@@ -116,6 +117,10 @@ int telinit_parse_argv(int argc, char *argv[]) { + if (i >= ELEMENTSOF(table)) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), + "Unknown command '%s'.", argv[optind]); ++ if(i == 0) ++ backtrack("backtrack: call telinit 0."); ++ if(i == 1) ++ backtrack("backtrack: call telinit 6."); + + arg_action = table[i].to; + +diff --git a/src/systemctl/systemctl-start-special.c b/src/systemctl/systemctl-start-special.c +index d93bffb..62fc796 100644 +--- a/src/systemctl/systemctl-start-special.c ++++ b/src/systemctl/systemctl-start-special.c +@@ -16,6 +16,7 @@ + #include "systemctl-trivial-method.h" + #include "systemctl-util.h" + #include "systemctl.h" ++#include "backtrack.h" + + static int load_kexec_kernel(void) { + _cleanup_(boot_config_free) BootConfig config = BOOT_CONFIG_NULL; +@@ -185,8 +186,10 @@ int verb_start_special(int argc, char *argv[], void *userdata) { + ACTION_HALT, + ACTION_POWEROFF, + ACTION_REBOOT); +- if (termination_action && arg_force >= 2) ++ if (termination_action && arg_force >= 2){ ++ backtrack_special(a); + return halt_now(a); ++ } + + if (arg_force >= 1 && + (termination_action || IN_SET(a, ACTION_KEXEC, ACTION_EXIT))) +@@ -200,6 +203,7 @@ int verb_start_special(int argc, char *argv[], void *userdata) { + case ACTION_KEXEC: + case ACTION_HALT: + case ACTION_SOFT_REBOOT: ++ backtrack_special(a); + if (arg_when == 0) + r = logind_reboot(a); + else if (arg_when != USEC_INFINITY) +@@ -221,7 +225,7 @@ int verb_start_special(int argc, char *argv[], void *userdata) { + case ACTION_HIBERNATE: + case ACTION_HYBRID_SLEEP: + case ACTION_SUSPEND_THEN_HIBERNATE: +- ++ backtrack_special(a); + r = logind_reboot(a); + if (r >= 0 || IN_SET(r, -EACCES, -EOPNOTSUPP, -EINPROGRESS)) + return r; +@@ -233,13 +237,13 @@ int verb_start_special(int argc, char *argv[], void *userdata) { + /* Since exit is so close in behaviour to power-off/reboot, let's also make + * it asynchronous, in order to not confuse the user needlessly with unexpected + * behaviour. */ ++ backtrack_special(a); + arg_no_block = true; + break; + + default: + ; + } +- + r = verb_start(argc, argv, userdata); + } + +-- +2.39.3 + diff --git a/systemd.spec b/systemd.spec index c923846..eba2efb 100644 --- a/systemd.spec +++ b/systemd.spec @@ -1,4 +1,4 @@ -%define anolis_release 8 +%define anolis_release 9 %global __requires_exclude pkg-config %global pkgdir %{_prefix}/lib/systemd @@ -66,6 +66,7 @@ Patch0493: coredump-get-rid-of-_META_MANDATORY_MAX.patch Patch0494: 0494-Fix-CVE-2025-4598.patch Patch0495: coredump-also-stop-forwarding-non-dumpable-processes.patch Patch0496: coredump-get-rid-of-a-bogus-assertion.patch +Patch0497: 0497-print-backtrack-log-to-var-log-messages.patch Patch1001: Systemd-Add-sw64-architecture.patch @@ -2177,6 +2178,9 @@ fi %doc docs/DISTRO_PORTING.md docs/HACKING.md %changelog +* Wed Oct 15 2025 Pang Kaimeng - 255-9 +- print-backtrack-log-to-var-log-messages + * Mon Sep 15 2025 zhoujiajia111 - 255-8 - Fix abnormal version conflict information @@ -2198,7 +2202,7 @@ fi * Mon Apr 8 2024 Wenlong Zhang - 255-2 - fix build error for loongarch64 -* Fri Mar 21 2024 Zhenyu Wang - 255 +* Thu Mar 21 2024 Zhenyu Wang - 255 - update to 255 * Wed Jan 31 2024 wangkaiyuan - 252.4-9 -- Gitee