public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Configurable Magic Sysrq
@ 2004-10-29  9:39 Jan Kara
  2004-10-29  9:46 ` Andrew Morton
  2004-10-31 18:52 ` Pavel Machek
  0 siblings, 2 replies; 20+ messages in thread
From: Jan Kara @ 2004-10-29  9:39 UTC (permalink / raw)
  To: linux-kernel; +Cc: akpm

[-- Attachment #1: Type: text/plain, Size: 542 bytes --]

  Hello,

  I know about a few people who would like to use some functionality of
the Magic Sysrq but don't want to enable all the functions it provides.
So I wrote a patch which should allow them to do so. It allows to
configure available functions of Sysrq via /proc/sys/kernel/sysrq (the
interface is backward compatible). If you think it's useful then use it :)
Andrew, do you think it can go into mainline or it's just an overdesign?

			Thanks in advance for comments, bugreports
								Honza

-- 
Jan Kara <jack@suse.cz>
SuSE CR Labs

[-- Attachment #2: enable-sysrq.diff --]
[-- Type: text/plain, Size: 5649 bytes --]

Enable configuration of sysrq functions via /proc/sys/kernel/sysrq.

Signed-off-by: Jan Kara <jack@suse.cz>

diff -ru linux-2.6.9/Documentation/sysrq.txt linux-2.6.9-sysrq/Documentation/sysrq.txt
--- linux-2.6.9/Documentation/sysrq.txt	2004-10-18 23:54:08.000000000 +0200
+++ linux-2.6.9-sysrq/Documentation/sysrq.txt	2004-10-22 18:58:07.924933784 +0200
@@ -10,13 +10,27 @@
 *  How do I enable the magic SysRq key?
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 You need to say "yes" to 'Magic SysRq key (CONFIG_MAGIC_SYSRQ)' when
-configuring the kernel. When running on a kernel with SysRq compiled in, it
-may be DISABLED at run-time using following command:
+configuring the kernel. When running a kernel with SysRq compiled in,
+/proc/sys/kernel/sysrq controls the functions allowed to be invoked via
+the SysRq key. By default the file contains 1 which means that every
+possible SysRq request is allowed (in older versions SysRq was disabled
+by default, and you were required to specifically enable it at run-time
+but this is not the case any more). Here is the list of possible values
+in /proc/sys/kernel/sysrq:
+   0 - disable sysrq completely
+   1 - enable all functions of sysrq
+  >1 - bitmask of allowed sysrq functions (see below for detailed function
+       description):
+          2 - enable control of console logging level
+          4 - enable control of keyboard (SAK, unraw)
+          8 - enable debugging dumps of processes etc.
+         16 - enable sync command
+         32 - enable remount read-only
+         64 - enable signalling of processes (term, kill)
+        128 - allow reboot
 
-        echo "0" > /proc/sys/kernel/sysrq
-
-Note that previous versions disabled sysrq by default, and you were required
-to specifically enable it at run-time. That is not the case any longer.
+You can set the value in the file by the following command:
+    echo "number" >/proc/sys/kernel/sysrq
 
 *  How do I use the magic SysRq key?
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff -ru linux-2.6.9/drivers/char/sysrq.c linux-2.6.9-sysrq/drivers/char/sysrq.c
--- linux-2.6.9/drivers/char/sysrq.c	2004-10-18 23:55:06.000000000 +0200
+++ linux-2.6.9-sysrq/drivers/char/sysrq.c	2004-10-22 14:47:25.000000000 +0200
@@ -38,6 +38,15 @@
 
 extern void reset_vc(unsigned int);
 
+/* 0x0001 is reserved for enable everything */
+#define SYSRQ_ENABLE_LOG	0x0002
+#define SYSRQ_ENABLE_KEYBOARD	0x0004
+#define SYSRQ_ENABLE_DUMP	0x0008
+#define SYSRQ_ENABLE_SYNC	0x0010
+#define SYSRQ_ENABLE_REMOUNT	0x0020
+#define SYSRQ_ENABLE_SIGNAL	0x0040
+#define SYSRQ_ENABLE_BOOT	0x0080
+
 /* Whether we react on sysrq keys or just ignore them */
 int sysrq_enabled = 1;
 
@@ -58,6 +67,7 @@
 	.handler	= sysrq_handle_loglevel,
 	.help_msg	= "loglevel0-8",
 	.action_msg	= "Changing Loglevel",
+	.enable_mask	= SYSRQ_ENABLE_LOG,
 };
 
 
@@ -74,6 +84,7 @@
 	.handler	= sysrq_handle_SAK,
 	.help_msg	= "saK",
 	.action_msg	= "SAK",
+	.enable_mask	= SYSRQ_ENABLE_KEYBOARD,
 };
 #endif
 
@@ -91,6 +102,7 @@
 	.handler	= sysrq_handle_unraw,
 	.help_msg	= "unRaw",
 	.action_msg	= "Keyboard mode set to XLATE",
+	.enable_mask	= SYSRQ_ENABLE_KEYBOARD,
 };
 #endif /* CONFIG_VT */
 
@@ -105,6 +117,7 @@
 	.handler	= sysrq_handle_reboot,
 	.help_msg	= "reBoot",
 	.action_msg	= "Resetting",
+	.enable_mask	= SYSRQ_ENABLE_BOOT,
 };
 
 static void sysrq_handle_sync(int key, struct pt_regs *pt_regs,
@@ -117,6 +130,7 @@
 	.handler	= sysrq_handle_sync,
 	.help_msg	= "Sync",
 	.action_msg	= "Emergency Sync",
+	.enable_mask	= SYSRQ_ENABLE_SYNC,
 };
 
 static void sysrq_handle_mountro(int key, struct pt_regs *pt_regs,
@@ -129,6 +143,7 @@
 	.handler	= sysrq_handle_mountro,
 	.help_msg	= "Unmount",
 	.action_msg	= "Emergency Remount R/O",
+	.enable_mask	= SYSRQ_ENABLE_REMOUNT,
 };
 
 /* END SYNC SYSRQ HANDLERS BLOCK */
@@ -146,6 +161,7 @@
 	.handler	= sysrq_handle_showregs,
 	.help_msg	= "showPc",
 	.action_msg	= "Show Regs",
+	.enable_mask	= SYSRQ_ENABLE_DUMP,
 };
 
 
@@ -158,6 +174,7 @@
 	.handler	= sysrq_handle_showstate,
 	.help_msg	= "showTasks",
 	.action_msg	= "Show State",
+	.enable_mask	= SYSRQ_ENABLE_DUMP,
 };
 
 
@@ -170,6 +187,7 @@
 	.handler	= sysrq_handle_showmem,
 	.help_msg	= "showMem",
 	.action_msg	= "Show Memory",
+	.enable_mask	= SYSRQ_ENABLE_DUMP,
 };
 
 /* SHOW SYSRQ HANDLERS BLOCK */
@@ -200,6 +218,7 @@
 	.handler	= sysrq_handle_term,
 	.help_msg	= "tErm",
 	.action_msg	= "Terminate All Tasks",
+	.enable_mask	= SYSRQ_ENABLE_SIGNAL,
 };
 
 static void sysrq_handle_kill(int key, struct pt_regs *pt_regs,
@@ -212,6 +231,7 @@
 	.handler	= sysrq_handle_kill,
 	.help_msg	= "kIll",
 	.action_msg	= "Kill All Tasks",
+	.enable_mask	= SYSRQ_ENABLE_SIGNAL,
 };
 
 /* END SIGNAL SYSRQ HANDLERS BLOCK */
@@ -331,9 +351,13 @@
 
         op_p = __sysrq_get_key_op(key);
         if (op_p) {
-		printk ("%s\n", op_p->action_msg);
-		console_loglevel = orig_log_level;
-		op_p->handler(key, pt_regs, tty);
+		if (sysrq_enabled == 1 || sysrq_enabled & op_p->enable_mask) {
+			printk ("%s\n", op_p->action_msg);
+			console_loglevel = orig_log_level;
+			op_p->handler(key, pt_regs, tty);
+		}
+		else
+			printk("This sysrq operation is disabled.\n");
 	} else {
 		printk("HELP : ");
 		/* Only print the help msg once per handler */
diff -ru linux-2.6.9/include/linux/sysrq.h linux-2.6.9-sysrq/include/linux/sysrq.h
--- linux-2.6.9/include/linux/sysrq.h	2004-10-18 23:53:06.000000000 +0200
+++ linux-2.6.9-sysrq/include/linux/sysrq.h	2004-10-22 14:47:25.000000000 +0200
@@ -20,6 +20,7 @@
 	void (*handler)(int, struct pt_regs *, struct tty_struct *);
 	char *help_msg;
 	char *action_msg;
+	int enable_mask;
 };
 
 #ifdef CONFIG_MAGIC_SYSRQ

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2004-11-01  9:29 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-29  9:39 [PATCH] Configurable Magic Sysrq Jan Kara
2004-10-29  9:46 ` Andrew Morton
2004-10-29 10:17   ` Jan Kara
2004-10-29 10:24     ` Andrew Morton
2004-10-29 20:09       ` Dave Jones
2004-10-30  6:45         ` Olaf Hering
2004-11-01  9:29         ` Jan Kara
2004-10-31 18:59     ` Pavel Machek
2004-10-29 11:34   ` Måns Rullgård
2004-10-29 13:35     ` Jan Kara
2004-10-29 13:44       ` Måns Rullgård
2004-10-29 14:33       ` Jan Engelhardt
2004-10-29 14:50         ` Jan Kara
2004-10-29 14:53           ` Jan Engelhardt
2004-11-01  9:09             ` Jan Kara
2004-10-31 18:52 ` Pavel Machek
2004-10-31 19:09   ` Dmitry Torokhov
2004-10-31 19:44     ` Pavel Machek
2004-10-31 19:12   ` Andreas Schwab
2004-11-01  0:52   ` Tim Connors

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox