我试图在Ubuntu18.04上设置systemd-coredump,以便捕获并记录C++应用程序的崩溃,以便进行调试。
到目前为止,我已经从apt安装了systemd-coredump 237-3ubuntu10.47版本,并通过向应用程序发送分段故障信号来触发崩溃:
sudo kill -s SEGV <application-pid>然而,我并没有像我预期的那样在/var/crash/中看到一个转储。运行sudo coredumpctl list也不会显示任何崩溃;它只响应No coredumps found.。
我读到了日志存储在日记中的the systemd-coredump manual,所以我用sudo journalctl打开它,并搜索我的kill命令。之后,我发现了以下错误消息:
Jun 30 21:53:41 ip-100-90-52-170 kernel: Core dump to |/usr/lib/systemd/systemd-coredump pipe failed我检查了/usr/lib/systemd/目录,发现systemd-coredump不存在。但是,我不确定这个...file?..directory?应该是动态创造的。文件/目录创建过程中是否存在权限问题,因为/usr/lib/systemd/是由root拥有的,而我的应用程序是以非特权用户的身份运行的?
这是我的kernel.core_pattern配置,/usr/lib/sysctl.d/50-coredump.conf。(这是默认的。)
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
# See sysctl.d(5) for the description of the files in this directory,
# and systemd-coredump(8) and core(5) for the explanation of the
# setting below.
kernel.core_pattern=|/lib/systemd/systemd-coredump %P %u %g %s %t 9223372036854775808 %e以及我的coredump配置,/etc/systemd/coredump.conf (也是默认的)。
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See coredump.conf(5) for details.
[Coredump]
#Storage=external
#Compress=yes
#ProcessSizeMax=2G
#ExternalSizeMax=2G
#JournalSizeMax=767M
#MaxUse=
#KeepFree=我还确认在/etc/systemd/coredump.conf.d/中没有配置片段(实际上,没有这样的目录)。
发布于 2021-06-30 23:08:02
core_pattern:My 被 /etc/sysctl.d/core.conf**.**推翻
通过重新阅读the systemd-coredump manual,我最终意识到/usr/lib/systemd/systemd-coredump不仅仅是一个记录转储的文件或目录,而是应该是systemd-coredump二进制文件本身。所以很明显,它不存在的事实是一个问题。
我还注意到日志中的错误显示内核正在/usr/lib/systemd/systemd-coredump中查找/usr/lib/systemd/systemd-coredump二进制文件,而不是像我的配置所示的/lib/systemd/systemd-coredump。事实上,在/lib/systemd/systemd-coredump中确实存在一个二进制文件。
因此,我的下一步是弄清楚内核为什么要使用/usr/lib/systemd/systemd-coredump。为此,我使用grep执行了递归文件搜索。我找到的唯一包含配置错误的二进制路径的配置文件是/etc/sysctl.d/core.conf。
kernel.core_pattern = |/usr/lib/systemd/systemd-coredump --backtrace %p %u %g %s %t %e
kernel.core_uses_pid = 0
fs.suid_dumpable = 2
suid_dumpable = 2虽然文件kernel.core_pattern在the systemd-coredump manual中没有提到,但显然它是覆盖core_pattern的另一种方式,因为在我注释掉了 /etc/sysctl.d/core.conf 中的core_pattern行并重新启动了VM之后,我能够崩溃我的应用程序并看到转储(日志中没有错误)!
$ sudo coredumpctl list
TIME PID UID GID SIG COREFILE EXE
Wed 2021-06-30 22:56:23 UTC 23796 888 888 11 present <my-application>发布于 2021-09-15 09:01:58
您可以从以下事实得出结论:可执行的systemd不在/usr/lib/systemd中,它不是一个问题。是的,您的系统正在寻找那个位置上的可执行文件,没有找到它,这会导致错误消息。还有一个文件可以设置这个位置: /usr/lib/sysctl/50-coredump.conf。我想你会在那里找到合适的位置:
/lib/systemd/systemd-coredump.conf
斯特夫
https://stackoverflow.com/questions/68202476
复制相似问题