[PATCH] RFC: Pass process information to userspace coredump

From: Viktor Rosendahl
Date: Fri Oct 17 2008 - 11:40:31 EST


When dumping core to pipe, set CORE_{EXE,PID,SIG,UID,GID} environment
variables. The userspace helper can then use them or look in
/proc/${CORE_PID} for more information.

This code is from the Nokia N810 kernel; I did not write it.

Signed-off-by: Viktor Rosendahl <viktor.rosendahl@xxxxxxxxx>
---
fs/exec.c | 18 +++++++++++++++++-
1 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/fs/exec.c b/fs/exec.c
index a41e790..3a9625d 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1771,6 +1771,14 @@ int do_coredump(long signr, int exit_code, struct pt_regs * regs)
goto fail_unlock;

if (ispipe) {
+ char env_exe[64];
+ char env_pid[16], env_sig[16];
+ char env_uid[16], env_gid[16];
+ char *envp[] = { env_exe,
+ env_pid, env_sig,
+ env_uid, env_gid,
+ NULL };
+
helper_argv = argv_split(GFP_KERNEL, corename+1, &helper_argc);
/* Terminate the string before the first option */
delimit = strchr(corename, ' ');
@@ -1789,8 +1797,16 @@ int do_coredump(long signr, int exit_code, struct pt_regs * regs)

core_limit = RLIM_INFINITY;

+ snprintf(env_exe, sizeof(env_exe), "CORE_EXE=%s",
+ current->comm);
+ snprintf(env_pid, sizeof(env_pid), "CORE_PID=%d",
+ current->tgid);
+ snprintf(env_sig, sizeof(env_sig), "CORE_SIG=%ld", signr);
+ snprintf(env_uid, sizeof(env_uid), "CORE_UID=%u", current->uid);
+ snprintf(env_gid, sizeof(env_gid), "CORE_GID=%u", current->gid);
+
/* SIGPIPE can happen, but it's just never processed */
- if (call_usermodehelper_pipe(corename+1, helper_argv, NULL,
+ if (call_usermodehelper_pipe(corename+1, helper_argv, envp,
&file)) {
printk(KERN_INFO "Core dump to %s pipe failed\n",
corename);
--
1.5.6.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/