I'm trying to set up systemd-coredump on Ubuntu 18.04, so that I can catch and log crashes of my C++ application for debugging.
So far, I've installed systemd-coredump version 237-3ubuntu10.47 from apt, and I'm able to trigger a crash by sending my application a segmentation fault signal:
sudo kill -s SEGV <application-pid>
However, I don't see a dump in /var/crash/ as I expected. Running sudo coredumpctl list does not show any crashes, either; it only replies No coredumps found.
I read the systemd-coredump manual that logs are stored in the journal, so I opened it with sudo journalctl and search for my kill command. After it, I found this error message:
Jun 30 21:53:41 ip-100-90-52-170 kernel: Core dump to |/usr/lib/systemd/systemd-coredump pipe failed
I examined the directory /usr/lib/systemd/, and I found that systemd-coredump did not exist. However, I'm not sure if this ...file? ..directory? is supposed to be created on the fly. Is there perhaps a permission issue during file/directory creation, because /usr/lib/systemd/ is owned by root, while my application runs as an unprivileged user?
Here is my kernel.core_pattern configuration, /usr/lib/sysctl.d/50-coredump.conf. (It's the default.)
# 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
And my coredump configuration, /etc/systemd/coredump.conf (also the default).
# 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=
I also confirmed that I have no config snippets in /etc/systemd/coredump.conf.d/ (In fact, there is no such directory.)
TL;DR: My
core_patternwas being overridden by/etc/sysctl.d/core.conf.From re-reading the
systemd-coredumpmanual, I eventually realized that/usr/lib/systemd/systemd-coredumpwas not just a file or directory where dumps were logged, but it was supposed to be thesystemd-coredumpbinary, itself. So obviously, the fact that it was not present was a problem.I also noticed that the error in the journal showed that the kernel was looking for the
systemd-coredumpbinary in/usr/lib/systemd/systemd-coredump, not/lib/systemd/systemd-coredump, as my configuration showed. And in fact, a binary did exist at/lib/systemd/systemd-coredump.Therefore, my next step was to figure out why the kernel was trying to use
/usr/lib/systemd/systemd-coredump. For that, I performed a recursive file search withgrep. The only config file I found containing the misconfigured binary path was/etc/sysctl.d/core.conf:Although the file
/etc/sysctl.d/core.confis not mentioned in thesystemd-coredumpmanual, it is apparently another way to override thecore_pattern, because after I commented out thekernel.core_patternline in/etc/sysctl.d/core.confand rebooted my VM, I was able to crash my application and see the dumps (and no error in the journal)! :)