Re: Wanted: Multithreaded coredump patch

From: Terje Malmedal (tm@funcom.com)
Date: Thu Jul 13 2000 - 10:40:40 EST


> Could somebody please give me a pointer to a patch to allow
> multithreaded apps dump core under linux 2.2.x?

I wrote this some time ago, Do "echo 1 > /proc/sys/kernel/coredumptype"
and coredumps will go to core.<programname>.<pid>

diff -ur linux-2.2.16/fs/binfmt_elf.c linux/fs/binfmt_elf.c
--- linux-2.2.16/fs/binfmt_elf.c Wed Jun 7 23:26:43 2000
+++ linux/fs/binfmt_elf.c Fri Jun 9 12:47:15 2000
@@ -1061,6 +1061,42 @@
 #define DUMP_SEEK(off) \
         if (!dump_seek(file, (off))) \
                 goto close_coredump;
+
+static int elf_core_dump2(long signr, struct pt_regs * regs);
+void force_sig(int sig, struct task_struct *p);
+
+int coredumptype = 0; /* Meaning: 0 normal core file.
+ 1 dump all threads to core.processname.pid
+ */
+/* First make current process dump core as normal, then we hunt down
+ all threads which share the same memory map and force them to
+ core as well
+
+ Terje Malmedal <tm@funcom.com>
+*/
+
+static int elf_core_dump(long signr, struct pt_regs * regs)
+{
+ struct task_struct *tsk = current->next_task;
+ int ret = 0;
+ ret = elf_core_dump2(signr,regs);
+ if(coredumptype == 1) {
+ read_lock(&tasklist_lock);
+ while(tsk && tsk != current) {
+ if(current->mm->mmap == tsk->mm->mmap) {
+#ifdef DEBUG
+ printk("Forcing SEGV to %d (%s)\n",
+ tsk->pid,tsk->comm);
+#endif
+ force_sig(SIGSEGV,tsk);
+ }
+ tsk = tsk->next_task;
+ }
+ read_unlock(&tasklist_lock);
+ }
+ return ret;
+}
+
 /*
  * Actual dumper
  *
@@ -1068,14 +1104,17 @@
  * and then they are actually written out. If we run out of core limit
  * we just truncate.
  */
-static int elf_core_dump(long signr, struct pt_regs * regs)
+static int elf_core_dump2(long signr, struct pt_regs * regs)
 {
         int has_dumped = 0;
         struct file *file;
         struct dentry *dentry;
         struct inode *inode;
         mm_segment_t fs;
- char corefile[6+sizeof(current->comm)];
+ char corefile[sizeof(current->comm)+16]; /* room for "core." +
+ current->comm +
+ pid(10 digits) +
+ '\0' */
         int segs;
         int i;
         size_t size;
@@ -1091,7 +1130,7 @@
 
         if (!current->dumpable ||
             limit < ELF_EXEC_PAGESIZE ||
- atomic_read(&current->mm->count) != 1)
+ atomic_read(&current->mm->count) < 1)
                 return 0;
         current->dumpable = 0;
 
@@ -1143,12 +1182,14 @@
         fs = get_fs();
         set_fs(KERNEL_DS);
 
- memcpy(corefile,"core.",5);
-#if 0
- memcpy(corefile+5,current->comm,sizeof(current->comm));
-#else
- corefile[4] = '\0';
-#endif
+ if(coredumptype == 1) {
+ sprintf(corefile,"core.%s.%d",
+ current->comm,
+ current->pid);
+ } else {
+ sprintf(corefile,"core");
+ }
+
         file = filp_open(corefile, O_CREAT | 2 | O_TRUNC | O_NOFOLLOW, 0600);
         if (IS_ERR(file))
                 goto end_coredump;
diff -ur linux-2.2.16/include/linux/sysctl.h linux/include/linux/sysctl.h
--- linux-2.2.16/include/linux/sysctl.h Wed Jun 7 23:26:44 2000
+++ linux/include/linux/sysctl.h Fri Jun 9 12:44:19 2000
@@ -81,7 +81,7 @@
         KERN_CAP_BSET=14, /* int: capability bounding set */
         KERN_PANIC=15, /* int: panic timeout */
         KERN_REALROOTDEV=16, /* real root device to mount after initrd */
-
+ KERN_COREDUMPTYPE=17, /* what kind of coredumps do we wish to do */
         KERN_JAVA_INTERPRETER=19, /* path to Java(tm) interpreter */
         KERN_JAVA_APPLETVIEWER=20, /* path to Java(tm) appletviewer */
         KERN_SPARC_REBOOT=21, /* reboot command on Sparc */
diff -ur linux-2.2.16/kernel/sysctl.c linux/kernel/sysctl.c
--- linux-2.2.16/kernel/sysctl.c Wed Jun 7 23:26:44 2000
+++ linux/kernel/sysctl.c Fri Jun 9 12:44:19 2000
@@ -33,6 +33,7 @@
 
 /* External variables not in a header file. */
 extern int panic_timeout;
+extern int coredumptype;
 extern int console_loglevel, C_A_D;
 extern int bdf_prm[], bdflush_min[], bdflush_max[];
 extern char binfmt_java_interpreter[], binfmt_java_appletviewer[];
@@ -169,6 +170,8 @@
         {KERN_DOMAINNAME, "domainname", system_utsname.domainname, 64,
          0644, NULL, &proc_doutsstring, &sysctl_string},
         {KERN_PANIC, "panic", &panic_timeout, sizeof(int),
+ 0644, NULL, &proc_dointvec},
+ {KERN_COREDUMPTYPE, "coredumptype" , &coredumptype,sizeof(int),
          0644, NULL, &proc_dointvec},
 #ifdef CONFIG_PROC_FS
         {KERN_CAP_BSET, "cap-bound", &cap_bset, sizeof(kernel_cap_t),

-- 
 - Terje
tm@funcom.com

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



This archive was generated by hypermail 2b29 : Sat Jul 15 2000 - 21:00:19 EST