mirror of
https://github.com/systemd/systemd.git
synced 2024-12-26 03:22:00 +03:00
Merge pull request #29803 from poettering/coredump-message-tweaks
coredump: tweaks to log message & more
This commit is contained in:
commit
070243ecda
@ -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;
|
||||
|
||||
@ -793,60 +792,69 @@ static int submit_coredump(
|
||||
(void) coredump_vacuum(-1, arg_keep_free, arg_max_use);
|
||||
|
||||
/* Always stream the coredump to disk, if that's possible */
|
||||
r = save_external_coredump(context, input_fd,
|
||||
&filename, &coredump_node_fd, &coredump_fd,
|
||||
&coredump_size, &coredump_compressed_size, &truncated);
|
||||
if (r < 0)
|
||||
/* Skip whole core dumping part */
|
||||
goto log;
|
||||
written = save_external_coredump(
|
||||
context, input_fd,
|
||||
&filename, &coredump_node_fd, &coredump_fd,
|
||||
&coredump_size, &coredump_compressed_size, &truncated) >= 0;
|
||||
if (written) {
|
||||
/* If we could write it to disk we can now process it. */
|
||||
/* 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. */
|
||||
r = maybe_remove_external_coredump(filename, coredump_node_fd >= 0 ? coredump_compressed_size : coredump_size);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r == 0)
|
||||
(void) iovw_put_string_field(iovw, "COREDUMP_FILENAME=", filename);
|
||||
else if (arg_storage == COREDUMP_STORAGE_EXTERNAL)
|
||||
log_info("The core will not be stored: size %"PRIu64" is greater than %"PRIu64" (the configured maximum)",
|
||||
coredump_node_fd >= 0 ? coredump_compressed_size : coredump_size, arg_external_size_max);
|
||||
|
||||
/* 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. */
|
||||
r = maybe_remove_external_coredump(filename, coredump_node_fd >= 0 ? coredump_compressed_size : coredump_size);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r == 0)
|
||||
(void) iovw_put_string_field(iovw, "COREDUMP_FILENAME=", filename);
|
||||
else if (arg_storage == COREDUMP_STORAGE_EXTERNAL)
|
||||
log_info("The core will not be stored: size %"PRIu64" is greater than %"PRIu64" (the configured maximum)",
|
||||
coredump_node_fd >= 0 ? coredump_compressed_size : coredump_size, arg_external_size_max);
|
||||
/* Vacuum again, but exclude the coredump we just created */
|
||||
(void) coredump_vacuum(coredump_node_fd >= 0 ? coredump_node_fd : coredump_fd, arg_keep_free, arg_max_use);
|
||||
}
|
||||
|
||||
/* Vacuum again, but exclude the coredump we just created */
|
||||
(void) coredump_vacuum(coredump_node_fd >= 0 ? coredump_node_fd : coredump_fd, arg_keep_free, arg_max_use);
|
||||
|
||||
/* Now, let's drop privileges to become the user who owns the segfaulted process
|
||||
* and allocate the coredump memory under the user's uid. This also ensures that
|
||||
* the credentials journald will see are the ones of the coredumping user, thus
|
||||
* making sure the user gets access to the core dump. Let's also get rid of all
|
||||
* capabilities, if we run as root, we won't need them anymore. */
|
||||
/* Now, let's drop privileges to become the user who owns the segfaulted process and allocate the
|
||||
* coredump memory under the user's uid. This also ensures that the credentials journald will see are
|
||||
* the ones of the coredumping user, thus making sure the user gets access to the core dump. Let's
|
||||
* also get rid of all capabilities, if we run as root, we won't need them anymore. */
|
||||
r = change_uid_gid(context);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to drop privileges: %m");
|
||||
|
||||
/* Try to get a stack trace if we can */
|
||||
if (coredump_size > arg_process_size_max)
|
||||
log_debug("Not generating stack trace: core size %"PRIu64" is greater "
|
||||
"than %"PRIu64" (the configured maximum)",
|
||||
coredump_size, arg_process_size_max);
|
||||
else if (coredump_fd >= 0) {
|
||||
bool skip = startswith(context->meta[META_COMM], "systemd-coredum"); /* COMM is 16 bytes usually */
|
||||
if (written) {
|
||||
/* Try to get a stack trace if we can */
|
||||
if (coredump_size > arg_process_size_max)
|
||||
log_debug("Not generating stack trace: core size %"PRIu64" is greater "
|
||||
"than %"PRIu64" (the configured maximum)",
|
||||
coredump_size, arg_process_size_max);
|
||||
else if (coredump_fd >= 0) {
|
||||
bool skip = startswith(context->meta[META_COMM], "systemd-coredum"); /* COMM is 16 bytes usually */
|
||||
|
||||
(void) parse_elf_object(coredump_fd,
|
||||
context->meta[META_EXE],
|
||||
/* fork_disable_dump= */ skip, /* avoid loops */
|
||||
&stacktrace,
|
||||
&json_metadata);
|
||||
(void) parse_elf_object(coredump_fd,
|
||||
context->meta[META_EXE],
|
||||
/* fork_disable_dump= */ skip, /* avoid loops */
|
||||
&stacktrace,
|
||||
&json_metadata);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user