From: Lennart Poettering Date: Wed, 1 Nov 2023 08:55:40 +0000 (+0100) Subject: coredump: tweak coredump log message X-Git-Tag: v255-rc1~67^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6fea39bacc53de2b14f12b434d4a4907cbf554a2;p=thirdparty%2Fsystemd.git 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 --- diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c index a67d425c14e..281e7170c23 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