This patch makes systemd-coredump handle processes that have whitespace in their COMM fields.
fs/coredump.c when given %e (as systemd-coredump uses), will end up joining the process arguments into a string (along with the other fields), then will split the entire thing up on whitespace, and use it as the arguments to the coredump pipe handler. Previously, systemd-coredump would then reject them as having too many arguments. --- src/journal/coredump.c | 25 ++++++++++++++++++------- 1 files changed, 18 insertions(+), 7 deletions(-)
>From 5dddf91172edfdbe21e5135fa0f14a9e44c5a1d6 Mon Sep 17 00:00:00 2001 From: Colin Walters <walt...@verbum.org> Date: Tue, 30 Apr 2013 13:06:03 -0400 Subject: [PATCH 2/2] coredump: Handle programs with spaces in COMM This patch makes systemd-coredump handle processes that have whitespace in their COMM fields. fs/coredump.c when given %e (as systemd-coredump uses), will end up joining the process arguments into a string (along with the other fields), then will split the entire thing up on whitespace, and use it as the arguments to the coredump pipe handler. Previously, systemd-coredump would then reject them as having too many arguments. --- src/journal/coredump.c | 25 ++++++++++++++++++------- 1 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/journal/coredump.c b/src/journal/coredump.c index fd03e38..8f5c17f 100644 --- a/src/journal/coredump.c +++ b/src/journal/coredump.c @@ -49,9 +49,9 @@ enum { ARG_GID, ARG_SIGNAL, ARG_TIMESTAMP, - ARG_COMM, - _ARG_MAX + ARG_COMM_START }; +#define _ARG_MIN (ARG_COMM_START+1) static int divert_coredump(void) { _cleanup_fclose_ FILE *f = NULL; @@ -98,6 +98,7 @@ static int divert_coredump(void) { } int main(int argc, char* argv[]) { + int i; int r, j = 0; char *t; ssize_t n; @@ -106,17 +107,18 @@ int main(int argc, char* argv[]) { gid_t gid; struct iovec iovec[14]; size_t coredump_bufsize, coredump_size; + const char *comm_joined_str = NULL; _cleanup_free_ char *core_pid = NULL, *core_uid = NULL, *core_gid = NULL, *core_signal = NULL, *core_timestamp = NULL, *core_comm = NULL, *core_exe = NULL, *core_unit = NULL, *core_session = NULL, *core_message = NULL, *core_cmdline = NULL, *coredump_data = NULL; prctl(PR_SET_DUMPABLE, 0); - if (argc != _ARG_MAX) { + if (argc < _ARG_MIN) { log_set_target(LOG_TARGET_JOURNAL_OR_KMSG); log_open(); - log_error("Invalid number of arguments passed from kernel."); + log_error("Expected at least %u arguments passed from kernel, received %u", _ARG_MIN, argc); r = -EINVAL; goto finish; } @@ -182,9 +184,18 @@ int main(int argc, char* argv[]) { if (core_signal) IOVEC_SET_STRING(iovec[j++], core_signal); - core_comm = strappend("COREDUMP_COMM=", argv[ARG_COMM]); - if (core_comm) + core_comm = strappend("COREDUMP_COMM=", argv[ARG_COMM_START]); + if (core_comm) { + for (i = ARG_COMM_START+1; i < argc; i++) { + strextend(&core_comm, " ", argv[i], NULL); + if (!core_comm) + break; + } + } + if (core_comm) { IOVEC_SET_STRING(iovec[j++], core_comm); + comm_joined_str = core_comm + strlen("COREDUMP_COMM="); + } #ifdef HAVE_LOGIND if (sd_pid_get_session(pid, &t) >= 0) { @@ -220,7 +231,7 @@ int main(int argc, char* argv[]) { IOVEC_SET_STRING(iovec[j++], "MESSAGE_ID=fc2e22bc6ee647b6b90729ab34a250b1"); IOVEC_SET_STRING(iovec[j++], "PRIORITY=2"); - core_message = strjoin("MESSAGE=Process ", argv[ARG_PID], " (", argv[ARG_COMM], ") dumped core.", NULL); + core_message = strjoin("MESSAGE=Process ", argv[ARG_PID], " (", comm_joined_str, ") dumped core.", NULL); if (core_message) IOVEC_SET_STRING(iovec[j++], core_message); -- 1.7.1
_______________________________________________ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel