coredump.c revision 8c9571d0ae50656f730a5e37378d5c3dcf3b9789
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fend/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fend This file is part of systemd.
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fend Copyright 2012 Lennart Poettering
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fend systemd is free software; you can redistribute it and/or modify it
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fend under the terms of the GNU Lesser General Public License as published by
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fend the Free Software Foundation; either version 2.1 of the License, or
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fend (at your option) any later version.
0ce5630695a7aa568811a9dd0aceedd685f040dend systemd is distributed in the hope that it will be useful, but
42af92a661a06b3cebc88d585aad75064a309d51nd WITHOUT ANY WARRANTY; without even the implied warranty of
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fend MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fend Lesser General Public License for more details.
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fend You should have received a copy of the GNU Lesser General Public License
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fend along with systemd; If not, see <http://www.gnu.org/licenses/>.
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fend# include <lzma.h>
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fend/* The maximum size up to which we process coredumps */
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fend#define PROCESS_SIZE_MAX ((off_t) (2LLU*1024LLU*1024LLU*1024LLU))
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fend/* The maximum size up to which we leave the coredump around on
0ce5630695a7aa568811a9dd0aceedd685f040dend/* The maximum size up to which we store the coredump in the
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fend * journal */
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fend/* Make sure to not make this larger than the maximum journal entry
f73f2c2fae0ded6c8273c28d025ba8aa8136a0fend * size. See ENTRY_SIZE_MAX in journald-native.c. */
typedef enum CoredumpStorage {
static DEFINE_CONFIG_PARSE_ENUM(config_parse_coredump_storage, coredump_storage, CoredumpStorage, "Failed to parse storage setting");
static bool arg_compress = true;
static int parse_config(void) {
return config_parse(
NULL,
"/etc/systemd/coredump.conf",
NULL,
(void*) items,
NULL);
#ifdef HAVE_ACL
if (!acl) {
return -errno;
return -errno;
return -errno;
return -errno;
for (i = 0; i < _INFO_LEN; i++) {
r = -errno;
return -errno;
return -errno;
if (!filename)
return -errno;
static int save_external_coredump(
char **ret_filename,
int *ret_fd,
return log_oom();
return log_oom();
return log_oom();
return log_oom();
return log_oom();
if (!tmp)
return log_oom();
if (fd < 0) {
return -errno;
if (r == -E2BIG) {
log_error("Coredump of %s (%s) is larger than configured processing limit, refusing.", info[INFO_PID], info[INFO_COMM]);
goto fail;
log_error("Not enough disk space for coredump of %s (%s), refusing.", info[INFO_PID], info[INFO_COMM]);
goto fail;
goto fail;
goto fail;
goto uncompressed;
#ifdef HAVE_XZ
&& arg_compress) {
char *tmp2;
if (fd2 < 0) {
goto uncompressed;
goto fail2;
if (!fn2) {
log_oom();
goto fail2;
goto fail2;
goto fail;
fail:
ssize_t n;
return -errno;
if (!field) {
return -ENOMEM;
return -EIO;
log_open();
r = -EINVAL;
goto finish;
parse_config();
goto finish;
goto finish;
goto finish;
goto finish;
goto finish;
goto finish;
if (core_unit)
log_open();
if (core_pid)
if (core_uid)
if (core_gid)
if (core_signal)
free(t);
if (core_session)
if (core_owner_uid)
free(t);
if (core_slice)
if (comm) {
if (core_comm)
if (exe) {
if (core_exe)
free(t);
if (core_cmdline)
free(t);
if (core_cgroup)
if (core_timestamp)
goto log;
goto finish;
const char *coredump_filename;
r = -errno;
goto finish;
#ifdef HAVE_ELFUTILS
core_message = strjoin("MESSAGE=Process ", info[INFO_PID], " (", comm, ") of user ", info[INFO_UID], " dumped core.\n\n", stacktrace, NULL);
if (!core_message)
log:
core_message = strjoin("MESSAGE=Process ", info[INFO_PID], " (", comm, ") of user ", info[INFO_UID], " dumped core.", NULL);
if (core_message)