SysRQ dumploGs (was: Oops when system shuts down)

Keith Owens (kaos@ocs.com.au)
Sun, 12 Apr 1998 13:10:36 +1000


On Mon, 06 Apr 1998 11:57:25 +0200,
David Woodhouse <Dave@imladris.demon.co.uk> wrote:
>
>s_dkling@student.uni-ulm.de said:
>> P.S. Is there any clever way to log all kernel message to a serial
>> console (after syslogd has exited!) so I don't have to write the oops
>> log by hand?
>
>Anyone want to volunteer to code a Magic-SysRq function which dumps the ring
>buffer to either serial or parallel port?

Against 2.1.95. SysRQ-g (dumploGs) sends logs files to all registered
consoles, you need to boot with a serial console to get the best
results. Currently just syslog, can be expanded to other log buffers,
ktrace 2.1.95 will use it when I get that out.

Index: linux/kernel/printk.c
--- linux/kernel/printk.c.orig Sun, 12 Apr 1998 00:37:34 +1000 keith (linux-2.1/X/4_printk.c 1.2.1.10 644) 95.3
+++ linux/kernel/printk.c Sun, 12 Apr 1998 12:56:19 +1000 keith (linux-2.1/X/4_printk.c 1.2.1.10 644) 95.3(w)
@@ -10,6 +10,8 @@
* elsewhere, in preparation for a serial line console (someday).
* Ted Ts'o, 2/11/93.
* Modified for sysctl support, 1/8/97, Chris Horn.
+ * syslog_to_console for SysRQ dumploGs. 12/04/1998.
+ * Keith Owens <kaos@ocs.com.au>
*/

#include <stdarg.h>
@@ -231,6 +233,46 @@
out:
unlock_kernel();
return error;
+}
+
+void syslog_to_console(void)
+{
+ /*
+ * Copy the syslog buffer to all registered consoles. Like
+ * sys_syslog, option 3 but to console instead of user. Raw data,
+ * no attempt to find record headers, message levels etc.
+ * Intended as a last ditch dump of syslog.
+ */
+ unsigned long i, j, count, flags;
+ char *p, buf[129]; /* copy log in 128 byte chunks */
+
+ /*
+ * The logged_chars, log_start, and log_size values may
+ * change from an interrupt, so we disable interrupts.
+ */
+ __save_flags(flags);
+ __cli();
+ count = LOG_BUF_LEN;
+ if (count > logged_chars)
+ count = logged_chars;
+ j = log_start + log_size - count;
+ __restore_flags(flags);
+ /* Race here, the log can change under us, we might dump garbage.
+ * Live with it, this is a last ditch output, waiting for locks
+ * could stop output. console_print should not require locks.
+ */
+ for (i = 0, p = buf; i < count; i++) {
+ *p++ = *((char *) log_buf+(j++ & (LOG_BUF_LEN-1)));
+ if (p == buf+sizeof(buf)-1) {
+ *p = '\0';
+ console_print(buf);
+ p = buf;
+ }
+ }
+ if (p != buf) {
+ *p = '\0';
+ console_print(buf);
+ }
}

spinlock_t console_lock;
Index: linux/drivers/char/sysrq.c
--- linux/drivers/char/sysrq.c.orig Sun, 22 Feb 1998 21:10:47 +1100 keith (linux-2.1/b/b/15_sysrq.c 1.3.4.2 644) 95.3
+++ linux/drivers/char/sysrq.c Sun, 12 Apr 1998 12:41:26 +1000 keith (linux-2.1/b/b/15_sysrq.c 1.3.4.2 644) 95.3(w)
@@ -6,6 +6,7 @@
*
* (c) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
* based on ideas by Pavel Machek <pavel@atrey.karlin.mff.cuni.cz>
+ * Add dumploGs. Keith Owens <kaos@ocs.com.au> 12/04/1998.
*/

#include <linux/config.h>
@@ -29,6 +30,7 @@
extern void wakeup_bdflush(int);
extern void reset_vc(unsigned int);
extern int console_loglevel;
+extern void syslog_to_console(void);
extern struct vfsmount *vfsmntlist;

/* Send a signal to all user processes */
@@ -126,6 +128,13 @@
send_sig_all(SIGKILL, 1);
orig_log_level = 8;
break;
+ case 'g': /* G -- dump all logs */
+ printk("Dump All Logs\n");
+ printk(KERN_INFO "DAL: syslog\n");
+ syslog_to_console();
+ /* add any other log dumps here */
+ printk("\n");
+ break;
default: /* Unknown: help */
if (kbd)
printk("unRaw ");
@@ -135,7 +144,7 @@
#ifdef CONFIG_APM
"Off "
#endif
- "Sync Unmount showPc showTasks showMem loglevel0-8 tErm kIll killalL\n");
+ "Sync Unmount showPc showTasks showMem loglevel0-8 tErm kIll killalL dumploGs\n");
/* Don't use 'A' as it's handled specially on the Sparc */
}

Index: linux/Documentation/sysrq.txt
--- linux/Documentation/sysrq.txt.orig Fri, 10 Apr 1998 18:58:25 +1000 keith (linux-2.1/J/b/36_sysrq.txt 1.1 644) 95.3
+++ linux/Documentation/sysrq.txt Sun, 12 Apr 1998 12:48:51 +1000 keith (linux-2.1/J/b/36_sysrq.txt 1.1 644) 95.3(w)
@@ -1,6 +1,7 @@
- MAGIC SYSRQ KEY DOCUMENTATION v1.0
+ MAGIC SYSRQ KEY DOCUMENTATION v1.1
------------------------------------
[Fri Apr 3 08:27:12 EST 1998]
+ [Sun Apr 12 12:37:10 EST 1998 - add dumploGs]

1. What is the magic SysRQ key?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -51,6 +52,8 @@
'l' - Send a SIGKILL to all processes, INCLUDING init. (Your system
will be non-functional after this.)

+'g' - Dumps log files to all registered consoles.
+
5. Okay, so what can I use them for?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Well, un'R'aw is very handy when your X server or a svgalib program crashes.
@@ -75,6 +78,10 @@
t'E'rm and k'I'll are useful if you have some sort of runaway process you
are unable to kill any other way, especially if it's spawning other
processes.
+
+dumplo'G's is useful when the system is hung and you want to see the
+log files. It is a good idea to have a serial console assigned to
+capture the result.

6. Sometimes SysRQ seems to get 'stuck' after using it, what can I do?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu