Create the /proc/<pid>/gen-core file that is the trigger for non-disruptive
application core dumps. Writing any value other than 1 to this file is
invalid.

Signed-off-by: Ananth N Mavinakayanahalli <ana...@in.ibm.com>
---
 fs/proc/Makefile       |    1 
 fs/proc/base.c         |    3 ++
 fs/proc/internal.h     |    3 ++
 fs/proc/proc_gencore.c |   65 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 72 insertions(+)

Index: utrace-13jul/fs/proc/Makefile
===================================================================
--- utrace-13jul.orig/fs/proc/Makefile
+++ utrace-13jul/fs/proc/Makefile
@@ -26,3 +26,4 @@ proc-$(CONFIG_PROC_VMCORE)    += vmcore.o
 proc-$(CONFIG_PROC_DEVICETREE) += proc_devtree.o
 proc-$(CONFIG_PRINTK)  += kmsg.o
 proc-$(CONFIG_PROC_PAGE_MONITOR)       += page.o
+proc-$(CONFIG_UTRACE)  += proc_gencore.o
Index: utrace-13jul/fs/proc/base.c
===================================================================
--- utrace-13jul.orig/fs/proc/base.c
+++ utrace-13jul/fs/proc/base.c
@@ -2558,6 +2558,9 @@ static const struct pid_entry tgid_base_
 #if defined(USE_ELF_CORE_DUMP) && defined(CONFIG_ELF_CORE)
        REG("coredump_filter", S_IRUGO|S_IWUSR, 
proc_coredump_filter_operations),
 #endif
+#ifdef CONFIG_UTRACE
+       REG("gen_core", S_IWUSR, proc_gen_core_operations),
+#endif
 #ifdef CONFIG_TASK_IO_ACCOUNTING
        INF("io",       S_IRUGO, proc_tgid_io_accounting),
 #endif
Index: utrace-13jul/fs/proc/internal.h
===================================================================
--- utrace-13jul.orig/fs/proc/internal.h
+++ utrace-13jul/fs/proc/internal.h
@@ -60,6 +60,9 @@ extern const struct file_operations proc
 extern const struct file_operations proc_pagemap_operations;
 extern const struct file_operations proc_net_operations;
 extern const struct inode_operations proc_net_inode_operations;
+#ifdef CONFIG_UTRACE
+extern const struct file_operations proc_gen_core_operations;
+#endif /* CONFIG_UTRACE */
 
 void free_proc_entry(struct proc_dir_entry *de);
 
Index: utrace-13jul/fs/proc/proc_gencore.c
===================================================================
--- /dev/null
+++ utrace-13jul/fs/proc/proc_gencore.c
@@ -0,0 +1,65 @@
+/*
+ * Non-disruptive application core dump
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) IBM Corporation, 2009
+ */
+
+#include <linux/seq_file.h>
+#include <linux/utrace.h>
+#include "internal.h"
+
+#include <asm/uaccess.h>
+
+static ssize_t gen_core_write(struct file *file, const char __user *buf,
+               size_t count, loff_t *ppos)
+{
+       struct task_struct *task;
+       char buffer[PROC_NUMBUF], *end;
+       unsigned int val;
+       int ret;
+
+       ret = -EFAULT;
+       memset(buffer, 0, sizeof(buffer));
+       if (count > sizeof(buffer) - 1)
+               count = sizeof(buffer) - 1;
+       if (copy_from_user(buffer, buf, count))
+               goto out_no_task;
+
+       ret = -EINVAL;
+       val = (unsigned int)simple_strtoul(buffer, &end, 0);
+       if (*end == '\n')
+               end++;
+       if ((end - buffer == 0) || (val == 0) || (val > 1))
+               goto out_no_task;
+
+       ret = -ESRCH;
+       task = get_proc_task(file->f_dentry->d_inode);
+       if (!task)
+               goto out_no_task;
+
+       ret = end - buffer;
+
+       /* TODO: call core dumper */
+
+       put_task_struct(task);
+out_no_task:
+       return ret;
+}
+
+const struct file_operations proc_gen_core_operations = {
+       .write          = gen_core_write,
+};

Reply via email to