summaryrefslogtreecommitdiffstats
path: root/src/coredump
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2023-11-01 09:55:40 +0100
committerLennart Poettering <lennart@poettering.net>2023-11-01 10:02:04 +0100
commit6fea39bacc53de2b14f12b434d4a4907cbf554a2 (patch)
tree236652c6874e3dd8984eae826917638fc14ffd68 /src/coredump
parentNEWS: fix typo (diff)
downloadsystemd-6fea39bacc53de2b14f12b434d4a4907cbf554a2.tar.xz
systemd-6fea39bacc53de2b14f12b434d4a4907cbf554a2.zip
coredump: tweak coredump log message
Let's not claim a process dumped core if that was disabled via resource limits. While we are at it, switch from stack to heap allocation for the log message, as it includes a stack trace which can be arbitrarily large. Fixes: #28559
Diffstat (limited to 'src/coredump')
-rw-r--r--src/coredump/coredump.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c
index a67d425c14..281e7170c2 100644
--- a/src/coredump/coredump.c
+++ b/src/coredump/coredump.c
@@ -778,10 +778,9 @@ static int submit_coredump(
_cleanup_close_ int coredump_fd = -EBADF, coredump_node_fd = -EBADF;
_cleanup_free_ char *filename = NULL, *coredump_data = NULL;
_cleanup_free_ char *stacktrace = NULL;
- char *core_message;
const char *module_name;
uint64_t coredump_size = UINT64_MAX, coredump_compressed_size = UINT64_MAX;
- bool truncated = false;
+ bool truncated = false, written = false;
JsonVariant *module_json;
int r;
@@ -800,6 +799,8 @@ static int submit_coredump(
/* Skip whole core dumping part */
goto log;
+ written = true;
+
/* If we don't want to keep the coredump on disk, remove it now, as later on we
* will lack the privileges for it. However, we keep the fd to it, so that we can
* still process it and log it. */
@@ -840,13 +841,23 @@ static int submit_coredump(
}
log:
- core_message = strjoina("Process ", context->meta[META_ARGV_PID],
- " (", context->meta[META_COMM], ") of user ",
- context->meta[META_ARGV_UID], " dumped core.",
- context->is_journald && filename ? "\nCoredump diverted to " : NULL,
- context->is_journald && filename ? filename : NULL);
+ _cleanup_free_ char *core_message = NULL;
+
+ core_message = strjoin(
+ "Process ", context->meta[META_ARGV_PID],
+ " (", context->meta[META_COMM],
+ ") of user ", context->meta[META_ARGV_UID],
+ written ? " dumped core." : " terminated abnormally without generating a coredump.");
+ if (!core_message)
+ return log_oom();
- core_message = strjoina(core_message, stacktrace ? "\n\n" : NULL, stacktrace);
+ if (context->is_journald && filename)
+ if (!strextend(&core_message, "\nCoredump diverted to ", filename))
+ return log_oom();
+
+ if (stacktrace)
+ if (!strextend(&core_message, "\n\n", stacktrace))
+ return log_oom();
if (context->is_journald)
/* We might not be able to log to the journal, so let's always print the message to another