Skip to contentSkip to conversation

logging coredump event

PATCH New Pengcheng Zou 1 participant 1 message Nov 1, 2005

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 logging coredump event

Hi,

sometimes daemon dies silently, dont know why, dont know when, dont know where the coredump is. attached with a patch (made by "Peter Wang" <[email protected]>) to make the sysadm's life a little bit easier, by logging the coredump event in syslog (if user allows).

when enabled (sysctl -w kernel.log_sig_exit=1), some syslog message will be generated if a process crash:

Nov  1 15:32:54 localhost kernel: pid 4649 (coredump), uid 0: exited on signal 

11 (core dumped)

and then the sysadm can react promptly.

trivial patch, but IMHO, very useful.

cheers,
-- Pengcheng

fs/exec.c +4 -0
diff -uprN linux-2.6.13.4.orig/fs/exec.c linux-2.6.13.4/fs/exec.c
@@ -58,6 +58,7 @@
 
 int core_uses_pid;
 char core_pattern[65] = "core";
+int log_sig_exit=0;
 int suid_dumpable = 0;
 
 EXPORT_SYMBOL(suid_dumpable);
@@ -1523,5 +1524,8 @@ fail_unlock:
 	current->fsuid = fsuid;
 	complete_all(&mm->core_done);
 fail:
+	if(log_sig_exit)
+		printk(KERN_INFO "pid %d (%s), uid %d: exited on signal %u %s\n",
+			current->pid,current->comm,current->uid,signr,retval?"(core dumped)":"");
 	return retval;
 }
include/linux/sysctl.h +1 -0
diff -uprN linux-2.6.13.4.orig/include/linux/sysctl.h linux-2.6.13.4/include/linux/sysctl.h
@@ -146,6 +146,7 @@ enum
 	KERN_RANDOMIZE=68, /* int: randomize virtual address space */
 	KERN_SETUID_DUMPABLE=69, /* int: behaviour of dumps for setuid core */
 	KERN_SPIN_RETRY=70,	/* int: number of spinlock retries */
+	KERN_LOG_SIG_EXIT=71, /* int: log when task exits because of some signals */
 };
 
 
kernel/sysctl.c +9 -0
diff -uprN linux-2.6.13.4.orig/kernel/sysctl.c linux-2.6.13.4/kernel/sysctl.c
@@ -60,6 +60,7 @@ extern int sysrq_enabled;
 extern int core_uses_pid;
 extern int suid_dumpable;
 extern char core_pattern[];
+extern int log_sig_exit;
 extern int cad_pid;
 extern int pid_max;
 extern int min_free_kbytes;
@@ -298,6 +299,14 @@ static ctl_table kern_table[] = {
 		.strategy	= &sysctl_string,
 	},
 	{
+		.ctl_name = KERN_LOG_SIG_EXIT,
+		.procname = "log_sig_exit",
+		.data  = &log_sig_exit,
+		.maxlen  = sizeof(int),
+		.mode  = 0644,
+		.proc_handler = &proc_dointvec,
+	},
+	{
 		.ctl_name	= KERN_TAINTED,
 		.procname	= "tainted",
 		.data		= &tainted,