public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Stateful Magic Sysrq Key
@ 2001-10-02  3:44 Crutcher Dunnavant
  2001-10-02  4:14 ` Simon Kirby
  2001-10-02  7:02 ` Ian Stirling
  0 siblings, 2 replies; 7+ messages in thread
From: Crutcher Dunnavant @ 2001-10-02  3:44 UTC (permalink / raw)
  To: linux-kernel, Linus Torvalds, Alan Cox

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

The following patch is a reworked patch which originated from Amazon.
It makes the sysrq key stateful, giving it the following behaviours:

A) If the magic key is pressed and held, every other key pressed will be
handled by the sysrq system. (This is the current behaviour).
B) If the magic key is pressed and released, the next key pressed will
be handled by the sysrq system.
C) If the magic key is pressed twice in series, it is passed through.

In addition, the patch allows registraiton of the the keycode which the
magic key lives on, through a proc entry.


This patch was developed to handle crappy KVM-alikes, which did one key
at a time, and had no SysRq key. However, it gives a good solution to a
common problem. Many keyboards are made cheaply, and do not support
having large numbers of keys pressed simultaneously, making the current
SysRq code almost useless on them.


There are two versions of the patch attached. One is for
linux-2.4.11-pre2, the other is for linux-2.4.10-ac3

-- 
Crutcher        <crutcher@datastacks.com>
GCS d--- s+:>+:- a-- C++++$ UL++++$ L+++$>++++ !E PS+++ PE Y+ PGP+>++++
    R-(+++) !tv(+++) b+(++++) G+ e>++++ h+>++ r* y+>*$

[-- Attachment #2: patch-2.4.11-pre2-stateful_sysrq --]
[-- Type: text/plain, Size: 5992 bytes --]

--- linux-2.4.11-pre2-stateful_sysrq/kernel/sysctl.c.stateful_sysrq	Mon Oct  1 23:13:44 2001
+++ linux-2.4.11-pre2-stateful_sysrq/kernel/sysctl.c	Mon Oct  1 23:23:58 2001
@@ -46,7 +46,7 @@
 extern int sysctl_overcommit_memory;
 extern int max_threads;
 extern int nr_queued_signals, max_queued_signals;
-extern int sysrq_enabled;
+extern struct sysrq_ctls_struct sysrq_ctls;
 extern int core_uses_pid;
 extern int cad_pid;
 
@@ -233,7 +233,9 @@
 	 0644, NULL, &proc_dointvec},
 #endif
 #ifdef CONFIG_MAGIC_SYSRQ
-	{KERN_SYSRQ, "sysrq", &sysrq_enabled, sizeof (int),
+	{KERN_SYSRQ, "sysrq", &sysrq_ctls.enabled, sizeof (int),
+	 0644, NULL, &proc_dointvec},
+	{KERN_SYSRQ, "sysrq-key", &sysrq_ctls.keycode, sizeof (sysrq_ctls.keycode),
 	 0644, NULL, &proc_dointvec},
 #endif	 
 	{KERN_CADPID, "cad_pid", &cad_pid, sizeof (int),
--- linux-2.4.11-pre2-stateful_sysrq/include/linux/sysctl.h.stateful_sysrq	Mon Oct  1 23:13:44 2001
+++ linux-2.4.11-pre2-stateful_sysrq/include/linux/sysctl.h	Mon Oct  1 23:23:58 2001
@@ -106,7 +106,7 @@
 	KERN_MSGMAX=35,         /* int: Maximum size of a messege */
 	KERN_MSGMNB=36,         /* int: Maximum message queue size */
 	KERN_MSGPOOL=37,        /* int: Maximum system message pool size */
-	KERN_SYSRQ=38,		/* int: Sysreq enable */
+	KERN_SYSRQ=38,		/* struct: Sysreq enable, Sysreq keycode */
 	KERN_MAX_THREADS=39,	/* int: Maximum nr of threads in the system */
  	KERN_RANDOM=40,		/* Random driver */
  	KERN_SHMALL=41,		/* int: Maximum size of shared memory */
--- linux-2.4.11-pre2-stateful_sysrq/include/linux/sysrq.h.stateful_sysrq	Mon Oct  1 23:13:44 2001
+++ linux-2.4.11-pre2-stateful_sysrq/include/linux/sysrq.h	Mon Oct  1 23:23:58 2001
@@ -26,6 +26,12 @@
 
 #ifdef CONFIG_MAGIC_SYSRQ
 
+/*  sysrq_ctls - controls aspects of the SYSRQ magic key hack*/
+struct sysrq_ctls_struct {
+	int enabled;
+	int keycode;
+};
+
 /* Generic SysRq interface -- you may call it from any device driver, supplying
  * ASCII code of the key, pointer to registers and kbd/tty structs (if they
  * are available -- else NULL's).
--- linux-2.4.11-pre2-stateful_sysrq/drivers/char/keyboard.c.stateful_sysrq	Tue Sep 18 16:39:51 2001
+++ linux-2.4.11-pre2-stateful_sysrq/drivers/char/keyboard.c	Mon Oct  1 23:23:58 2001
@@ -21,6 +21,12 @@
  *
  * 27-05-97: Added support for the Magic SysRq Key (Martin Mares)
  * 30-07-98: Dead keys redone, aeb@cwi.nl.
+ *
+ * 28-09-2001: Crutcher Dunnavant <crutcher+kernel@datastacks.com>
+ * Add stateful sysrq features, based upon work from:
+ *   Mathew Mills <mmills@amazon.com>
+ *   Norman Murray <nmurray@redhat.com>
+ *  
  */
 
 #include <linux/config.h>
@@ -157,7 +163,14 @@
 struct pt_regs * kbd_pt_regs;
 
 #ifdef CONFIG_MAGIC_SYSRQ
-static int sysrq_pressed;
+static enum {
+	UP_AND_CLEAR,
+	DOWN_AND_WAITING,
+	DOWN_AND_DONE,
+	UP_AND_WAITING,
+	DOWN_AND_PASS
+} sysrq_state;
+extern struct sysrq_ctls_struct sysrq_ctls;
 #endif
 
 static struct pm_dev *pm_kbd;
@@ -246,15 +259,69 @@
 	} else
 		rep = test_and_set_bit(keycode, key_down);
 
-#ifdef CONFIG_MAGIC_SYSRQ		/* Handle the SysRq Hack */
-	if (keycode == SYSRQ_KEY) {
-		sysrq_pressed = !up_flag;
-		goto out;
-	} else if (sysrq_pressed) {
-		if (!up_flag) {
-			handle_sysrq(kbd_sysrq_xlate[keycode], kbd_pt_regs, kbd, tty);
-			goto out;
+#ifdef CONFIG_MAGIC_SYSRQ               /* Handle the SysRq Hack */
+	/*
+	  Pressing magic + command key acts as a chorded command.
+	  Pressing and releasing magic without a command key acts sticky,
+	  using the next non-magic key as a command key
+	  Pressing magic twice without a command key passes the magic key
+	  through.
+	 */
+
+        if (sysrq_ctls.enabled) {
+		if (keycode == sysrq_ctls.keycode) switch(sysrq_state) {
+			case UP_AND_CLEAR:
+				sysrq_state = up_flag ? UP_AND_CLEAR :
+							DOWN_AND_WAITING;
+				/* consume the key event */
+				goto out;
+
+			case DOWN_AND_WAITING:
+				sysrq_state = up_flag ? UP_AND_WAITING :
+							DOWN_AND_WAITING;
+				/* consume the key event */
+				goto out;
+
+			case DOWN_AND_DONE:
+				sysrq_state = up_flag ? UP_AND_CLEAR :
+							DOWN_AND_DONE;
+				/* consume the key event */
+				goto out;
+
+			case DOWN_AND_PASS:
+			case UP_AND_WAITING:
+				sysrq_state = up_flag ? UP_AND_CLEAR :
+							DOWN_AND_PASS;
+				/* pass the key event through */
+				break;
+
+		} else switch(sysrq_state) {
+			case UP_AND_WAITING:
+			case DOWN_AND_WAITING:
+			case DOWN_AND_DONE:
+				if (!up_flag) {
+					handle_sysrq(kbd_sysrq_xlate[keycode],
+							kbd_pt_regs, kbd, tty);
+				}
+
+				if (sysrq_state == UP_AND_WAITING) {
+					sysrq_state = UP_AND_CLEAR;
+				} else {
+					sysrq_state = DOWN_AND_DONE;
+				}
+
+				/* consume the key event */
+				goto out;
+
+
+			case DOWN_AND_PASS:
+			case UP_AND_CLEAR:
+				/* pass the key event through */
+				break;
+
 		}
+        } else {
+		sysrq_state = UP_AND_CLEAR;
 	}
 #endif
 
--- linux-2.4.11-pre2-stateful_sysrq/drivers/char/sysrq.c.stateful_sysrq	Mon Oct  1 23:13:36 2001
+++ linux-2.4.11-pre2-stateful_sysrq/drivers/char/sysrq.c	Mon Oct  1 23:23:58 2001
@@ -32,12 +32,21 @@
 
 #include <asm/ptrace.h>
 
+/* for the SYSRQ_KEY definition */
+#include <asm/keyboard.h>
+
 extern void reset_vc(unsigned int);
 extern struct list_head super_blocks;
 
 /* Whether we react on sysrq keys or just ignore them */
-int sysrq_enabled = 1;
+struct sysrq_ctls_struct sysrq_ctls = {
+	/* Whether we react on sysrq keys or just ignore them */
+	enabled: 1,
 
+	/* The keycode for the magic key, referred to as sysrq */
+	keycode: SYSRQ_KEY,
+};
+ 
 /* Machine specific power off function */
 void (*sysrq_power_off)(void);
 
@@ -433,7 +442,7 @@
 
 void handle_sysrq(int key, struct pt_regs *pt_regs,
 		  struct kbd_struct *kbd, struct tty_struct *tty) {
-	if (!sysrq_enabled)
+	if (!sysrq_ctls.enabled)
 		return;
 
 	__sysrq_lock_table();
@@ -453,7 +462,7 @@
 	int orig_log_level;
 	int i, j;
 	
-	if (!sysrq_enabled)
+	if (!sysrq_ctls.enabled)
 		return;
 
 	orig_log_level = console_loglevel;

[-- Attachment #3: patch-2.4.10-ac3-stateful_sysrq --]
[-- Type: text/plain, Size: 6015 bytes --]

--- linux-2.4.10-ac3-stateful_sysrq/kernel/sysctl.c.stateful_sysrq	Mon Oct  1 23:14:25 2001
+++ linux-2.4.10-ac3-stateful_sysrq/kernel/sysctl.c	Mon Oct  1 23:25:53 2001
@@ -49,7 +49,7 @@
 extern int sysctl_overcommit_memory;
 extern int max_threads;
 extern int nr_queued_signals, max_queued_signals;
-extern int sysrq_enabled;
+extern struct sysrq_ctls_struct sysrq_ctls;
 extern int core_uses_pid;
 extern int cad_pid;
 
@@ -236,7 +236,9 @@
 	 0644, NULL, &proc_dointvec},
 #endif
 #ifdef CONFIG_MAGIC_SYSRQ
-	{KERN_SYSRQ, "sysrq", &sysrq_enabled, sizeof (int),
+	{KERN_SYSRQ, "sysrq", &sysrq_ctls.enabled, sizeof (int),
+	 0644, NULL, &proc_dointvec},
+	{KERN_SYSRQ, "sysrq-key", &sysrq_ctls.keycode, sizeof (sysrq_ctls.keycode),
 	 0644, NULL, &proc_dointvec},
 #endif	 
 	{KERN_CADPID, "cad_pid", &cad_pid, sizeof (int),
--- linux-2.4.10-ac3-stateful_sysrq/include/linux/sysctl.h.stateful_sysrq	Mon Oct  1 23:14:24 2001
+++ linux-2.4.10-ac3-stateful_sysrq/include/linux/sysctl.h	Mon Oct  1 23:25:53 2001
@@ -106,7 +106,7 @@
 	KERN_MSGMAX=35,         /* int: Maximum size of a messege */
 	KERN_MSGMNB=36,         /* int: Maximum message queue size */
 	KERN_MSGPOOL=37,        /* int: Maximum system message pool size */
-	KERN_SYSRQ=38,		/* int: Sysreq enable */
+	KERN_SYSRQ=38,		/* struct: Sysreq enable, Sysreq keycode */
 	KERN_MAX_THREADS=39,	/* int: Maximum nr of threads in the system */
  	KERN_RANDOM=40,		/* Random driver */
  	KERN_SHMALL=41,		/* int: Maximum size of shared memory */
--- linux-2.4.10-ac3-stateful_sysrq/include/linux/sysrq.h.stateful_sysrq	Mon Oct  1 23:14:24 2001
+++ linux-2.4.10-ac3-stateful_sysrq/include/linux/sysrq.h	Mon Oct  1 23:25:53 2001
@@ -26,6 +26,12 @@
 
 #ifdef CONFIG_MAGIC_SYSRQ
 
+/*  sysrq_ctls - controls aspects of the SYSRQ magic key hack*/
+struct sysrq_ctls_struct {
+	int enabled;
+	int keycode;
+};
+
 /* Generic SysRq interface -- you may call it from any device driver, supplying
  * ASCII code of the key, pointer to registers and kbd/tty structs (if they
  * are available -- else NULL's).
--- linux-2.4.10-ac3-stateful_sysrq/drivers/char/keyboard.c.stateful_sysrq	Mon Oct  1 23:14:06 2001
+++ linux-2.4.10-ac3-stateful_sysrq/drivers/char/keyboard.c	Mon Oct  1 23:25:53 2001
@@ -21,6 +21,12 @@
  *
  * 27-05-97: Added support for the Magic SysRq Key (Martin Mares)
  * 30-07-98: Dead keys redone, aeb@cwi.nl.
+ *
+ * 28-09-2001: Crutcher Dunnavant <crutcher+kernel@datastacks.com>
+ * Add stateful sysrq features, based upon work from:
+ *   Mathew Mills <mmills@amazon.com>
+ *   Norman Murray <nmurray@redhat.com>
+ *  
  */
 
 #include <linux/config.h>
@@ -159,7 +165,14 @@
 struct pt_regs * kbd_pt_regs;
 
 #ifdef CONFIG_MAGIC_SYSRQ
-static int sysrq_pressed;
+static enum {
+	UP_AND_CLEAR,
+	DOWN_AND_WAITING,
+	DOWN_AND_DONE,
+	UP_AND_WAITING,
+	DOWN_AND_PASS
+} sysrq_state;
+extern struct sysrq_ctls_struct sysrq_ctls;
 #endif
 
 static struct pm_dev *pm_kbd;
@@ -248,15 +261,69 @@
 	} else
 		rep = test_and_set_bit(keycode, key_down);
 
-#ifdef CONFIG_MAGIC_SYSRQ		/* Handle the SysRq Hack */
-	if (keycode == SYSRQ_KEY) {
-		sysrq_pressed = !up_flag;
-		goto out;
-	} else if (sysrq_pressed) {
-		if (!up_flag) {
-			handle_sysrq(kbd_sysrq_xlate[keycode], kbd_pt_regs, kbd, tty);
-			goto out;
+#ifdef CONFIG_MAGIC_SYSRQ               /* Handle the SysRq Hack */
+	/*
+	  Pressing magic + command key acts as a chorded command.
+	  Pressing and releasing magic without a command key acts sticky,
+	  using the next non-magic key as a command key
+	  Pressing magic twice without a command key passes the magic key
+	  through.
+	 */
+
+        if (sysrq_ctls.enabled) {
+		if (keycode == sysrq_ctls.keycode) switch(sysrq_state) {
+			case UP_AND_CLEAR:
+				sysrq_state = up_flag ? UP_AND_CLEAR :
+							DOWN_AND_WAITING;
+				/* consume the key event */
+				goto out;
+
+			case DOWN_AND_WAITING:
+				sysrq_state = up_flag ? UP_AND_WAITING :
+							DOWN_AND_WAITING;
+				/* consume the key event */
+				goto out;
+
+			case DOWN_AND_DONE:
+				sysrq_state = up_flag ? UP_AND_CLEAR :
+							DOWN_AND_DONE;
+				/* consume the key event */
+				goto out;
+
+			case DOWN_AND_PASS:
+			case UP_AND_WAITING:
+				sysrq_state = up_flag ? UP_AND_CLEAR :
+							DOWN_AND_PASS;
+				/* pass the key event through */
+				break;
+
+		} else switch(sysrq_state) {
+			case UP_AND_WAITING:
+			case DOWN_AND_WAITING:
+			case DOWN_AND_DONE:
+				if (!up_flag) {
+					handle_sysrq(kbd_sysrq_xlate[keycode],
+							kbd_pt_regs, kbd, tty);
+				}
+
+				if (sysrq_state == UP_AND_WAITING) {
+					sysrq_state = UP_AND_CLEAR;
+				} else {
+					sysrq_state = DOWN_AND_DONE;
+				}
+
+				/* consume the key event */
+				goto out;
+
+
+			case DOWN_AND_PASS:
+			case UP_AND_CLEAR:
+				/* pass the key event through */
+				break;
+
 		}
+        } else {
+		sysrq_state = UP_AND_CLEAR;
 	}
 #endif
 
--- linux-2.4.10-ac3-stateful_sysrq/drivers/char/sysrq.c.stateful_sysrq	Mon Oct  1 23:14:06 2001
+++ linux-2.4.10-ac3-stateful_sysrq/drivers/char/sysrq.c	Mon Oct  1 23:27:14 2001
@@ -32,12 +32,21 @@
 
 #include <asm/ptrace.h>
 
+/* for the SYSRQ_KEY definition */
+#include <asm/keyboard.h>
+
 extern void wakeup_bdflush(int);
 extern void reset_vc(unsigned int);
 extern struct list_head super_blocks;
 
 /* Whether we react on sysrq keys or just ignore them */
-int sysrq_enabled = 1;
+struct sysrq_ctls_struct sysrq_ctls = {
+	/* Whether we react on sysrq keys or just ignore them */
+	enabled: 1,
+  
+	/* The keycode for the magic key, referred to as sysrq */
+	keycode: SYSRQ_KEY,
+};
 
 /* Machine specific power off function */
 void (*sysrq_power_off)(void);
@@ -434,7 +443,7 @@
 
 void handle_sysrq(int key, struct pt_regs *pt_regs,
 		  struct kbd_struct *kbd, struct tty_struct *tty) {
-	if (!sysrq_enabled)
+	if (!sysrq_ctls.enabled)
 		return;
 
 	__sysrq_lock_table();
@@ -454,7 +463,7 @@
 	int orig_log_level;
 	int i, j;
 	
-	if (!sysrq_enabled)
+	if (!sysrq_ctls.enabled)
 		return;
 
 	orig_log_level = console_loglevel;

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

* Re: [PATCH] Stateful Magic Sysrq Key
  2001-10-02  3:44 Crutcher Dunnavant
@ 2001-10-02  4:14 ` Simon Kirby
  2001-10-02  7:02 ` Ian Stirling
  1 sibling, 0 replies; 7+ messages in thread
From: Simon Kirby @ 2001-10-02  4:14 UTC (permalink / raw)
  To: linux-kernel

On Mon, Oct 01, 2001 at 11:44:37PM -0400, Crutcher Dunnavant wrote:

> This patch was developed to handle crappy KVM-alikes, which did one key
> at a time, and had no SysRq key. However, it gives a good solution to a
> common problem. Many keyboards are made cheaply, and do not support
> having large numbers of keys pressed simultaneously, making the current
> SysRq code almost useless on them.

This iss sort of funny...A number of people at the office thought SysRq
was already stateful because there are a number of keyboards that do not
send a release event when alt+sysrq+another key are pressed
simultaneously....It actually makes it look like alt-sysrq is pressed
until alt-sysrq is actually pressed again without any keys following it. 
I suppose this patch makes this cheap keyboard flaw transparent. :)

Simon-

[  Stormix Technologies Inc.  ][  NetNation Communications Inc. ]
[       sim@stormix.com       ][       sim@netnation.com        ]
[ Opinions expressed are not necessarily those of my employers. ]

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

* Re: [PATCH] Stateful Magic Sysrq Key
  2001-10-02  3:44 Crutcher Dunnavant
  2001-10-02  4:14 ` Simon Kirby
@ 2001-10-02  7:02 ` Ian Stirling
  1 sibling, 0 replies; 7+ messages in thread
From: Ian Stirling @ 2001-10-02  7:02 UTC (permalink / raw)
  To: linux-kernel

> The following patch is a reworked patch which originated from Amazon.
> It makes the sysrq key stateful, giving it the following behaviours:

IMO, this is needed for broken keyboards, but in this exact form will
cause problems for those without them.
Pressing alt-sysrq accidentally is rare, but happens, typically when 
I'm going for vt-12 in a hurry, or cleaning out crumbs.
Normally this is fairly harmless, as most of the dangerous keys are
on a different quadrant.
Making it sticky makes accidents much more likely.

I'd suggest either making this behaviour optional, or making it so that
hitting alt-sysrq twice, without any other keys being pressed makes the
next key stick.


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

* Re: [PATCH] Stateful Magic Sysrq Key
@ 2001-10-02  8:48 willy tarreau
  2001-10-02 14:18 ` Crutcher Dunnavant
  0 siblings, 1 reply; 7+ messages in thread
From: willy tarreau @ 2001-10-02  8:48 UTC (permalink / raw)
  To: Ian Stirling, linux-kernel

> I'd suggest either making this behaviour optional,
or making it
> so that hitting alt-sysrq twice, without any other
keys being
> pressed makes the next key stick.

I agree with you that there's a risk. Mike Harris had
written a
patch for 2.2 which did something similar, but
slightly better 
IMO since it avoids risks of mis-press, handles
correctly
broken keyboards and keeps compatible with the
existing 
method. Basically, it allows the user to press Alt,
then SysRQ,
release SysRQ then press the desired key, and later
release
Alt. In fact, it only resets the "magic-key-mode" flag
after Alt
has been released, and doesn't bother when SysRq is
released.

I don't remember where it was available, but if
someone needs
it, I still have it here for 2.2.

Willy


___________________________________________________________
Do You Yahoo!? -- Un e-mail gratuit @yahoo.fr !
Yahoo! Courrier : http://fr.mail.yahoo.com

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

* Re: [PATCH] Stateful Magic Sysrq Key
  2001-10-02  8:48 [PATCH] Stateful Magic Sysrq Key willy tarreau
@ 2001-10-02 14:18 ` Crutcher Dunnavant
  2001-10-03 14:05   ` [PATCH] Stateful Magic Sysrq Key + Sticky Tag Crutcher Dunnavant
  0 siblings, 1 reply; 7+ messages in thread
From: Crutcher Dunnavant @ 2001-10-02 14:18 UTC (permalink / raw)
  To: linux-kernel

++ 02/10/01 10:48 +0200 - willy tarreau:
> > I'd suggest either making this behaviour optional,
> or making it
> > so that hitting alt-sysrq twice, without any other
> keys being
> > pressed makes the next key stick.
> 
> I agree with you that there's a risk. Mike Harris had
> written a
> patch for 2.2 which did something similar, but
> slightly better 
> IMO since it avoids risks of mis-press, handles
> correctly
> broken keyboards and keeps compatible with the
> existing 
> method. Basically, it allows the user to press Alt,
> then SysRQ,
> release SysRQ then press the desired key, and later
> release
> Alt. In fact, it only resets the "magic-key-mode" flag
> after Alt
> has been released, and doesn't bother when SysRq is
> released.

But this would require that alt be pressed. This is not acceptable on
exactly the sort of boards which require this patch.

I will look at adding a 'sysrq-sticky' entry to proc, which will do the
obvious thing. I think that this should address everyone's concerns.

-- 
Crutcher        <crutcher@datastacks.com>
GCS d--- s+:>+:- a-- C++++$ UL++++$ L+++$>++++ !E PS+++ PE Y+ PGP+>++++
    R-(+++) !tv(+++) b+(++++) G+ e>++++ h+>++ r* y+>*$

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

* Re: [PATCH] Stateful Magic Sysrq Key
       [not found] <20011002185016.90E271F9BA@zion.rivenstone.net>
@ 2001-10-03  4:23 ` Ian Stirling
  0 siblings, 0 replies; 7+ messages in thread
From: Ian Stirling @ 2001-10-03  4:23 UTC (permalink / raw)
  To: linux-kernel

> 
> On Tuesday 02 October 2001 03:02, Ian Stirling wrote:
> > > The following patch is a reworked patch which originated from Amazon.
> > > It makes the sysrq key stateful, giving it the following behaviours:
> >
> > IMO, this is needed for broken keyboards, but in this exact form will
> > cause problems for those without them.
<snip>
>     This behavior *is* optional -- both as a compile-time option and as a
> value in /proc/sys.

Sorry, I diddn't see it, I had a quick scan, and it seemed to me that
it was a replacement for the current magic-sysrq, not an alternative.

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

* [PATCH] Stateful Magic Sysrq Key + Sticky Tag
  2001-10-02 14:18 ` Crutcher Dunnavant
@ 2001-10-03 14:05   ` Crutcher Dunnavant
  0 siblings, 0 replies; 7+ messages in thread
From: Crutcher Dunnavant @ 2001-10-03 14:05 UTC (permalink / raw)
  To: linux-kernel; +Cc: Linus Torvalds, Alan Cox

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


This is the previous stateful sysrq patch, plus a 'sysrq-sticky' proc
entry, which defaults to off, that controls whether the stateful mode
will be used or not.

This reworked patch is against 2.4.11-pre2.

++ 02/10/01 10:18 -0400 - Crutcher Dunnavant:
> ++ 02/10/01 10:48 +0200 - willy tarreau:
> > > I'd suggest either making this behaviour optional,
> > or making it
> > > so that hitting alt-sysrq twice, without any other
> > keys being
> > > pressed makes the next key stick.
> > 
> > I agree with you that there's a risk. Mike Harris had
> > written a
> > patch for 2.2 which did something similar, but
> > slightly better 
> > IMO since it avoids risks of mis-press, handles
> > correctly
> > broken keyboards and keeps compatible with the
> > existing 
> > method. Basically, it allows the user to press Alt,
> > then SysRQ,
> > release SysRQ then press the desired key, and later
> > release
> > Alt. In fact, it only resets the "magic-key-mode" flag
> > after Alt
> > has been released, and doesn't bother when SysRq is
> > released.
> 
> But this would require that alt be pressed. This is not acceptable on
> exactly the sort of boards which require this patch.
> 
> I will look at adding a 'sysrq-sticky' entry to proc, which will do the
> obvious thing. I think that this should address everyone's concerns.
> 
> -- 
> Crutcher        <crutcher@datastacks.com>
> GCS d--- s+:>+:- a-- C++++$ UL++++$ L+++$>++++ !E PS+++ PE Y+ PGP+>++++
>     R-(+++) !tv(+++) b+(++++) G+ e>++++ h+>++ r* y+>*$
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

-- 
Crutcher        <crutcher@datastacks.com>
GCS d--- s+:>+:- a-- C++++$ UL++++$ L+++$>++++ !E PS+++ PE Y+ PGP+>++++
    R-(+++) !tv(+++) b+(++++) G+ e>++++ h+>++ r* y+>*$

[-- Attachment #2: patch-2.4.11-pre2-stateful_sticky_sysrq --]
[-- Type: text/plain, Size: 6975 bytes --]

diff -ur linux-2.4.11-pre2/drivers/char/keyboard.c linux-2.4.11-pre2-stateful_sysrq/drivers/char/keyboard.c
--- linux-2.4.11-pre2/drivers/char/keyboard.c	Tue Sep 18 16:39:51 2001
+++ linux-2.4.11-pre2-stateful_sysrq/drivers/char/keyboard.c	Wed Oct  3 00:15:08 2001
@@ -21,6 +21,12 @@
  *
  * 27-05-97: Added support for the Magic SysRq Key (Martin Mares)
  * 30-07-98: Dead keys redone, aeb@cwi.nl.
+ *
+ * 28-09-2001: Crutcher Dunnavant <crutcher+kernel@datastacks.com>
+ * Add stateful sysrq features, based upon work from:
+ *   Mathew Mills <mmills@amazon.com>
+ *   Norman Murray <nmurray@redhat.com>
+ *  
  */
 
 #include <linux/config.h>
@@ -157,7 +163,14 @@
 struct pt_regs * kbd_pt_regs;
 
 #ifdef CONFIG_MAGIC_SYSRQ
-static int sysrq_pressed;
+static enum {
+	UP_AND_CLEAR,
+	DOWN_AND_WAITING,
+	DOWN_AND_DONE,
+	UP_AND_WAITING,
+	DOWN_AND_PASS
+} sysrq_state;
+extern struct sysrq_ctls_struct sysrq_ctls;
 #endif
 
 static struct pm_dev *pm_kbd;
@@ -246,15 +259,76 @@
 	} else
 		rep = test_and_set_bit(keycode, key_down);
 
-#ifdef CONFIG_MAGIC_SYSRQ		/* Handle the SysRq Hack */
-	if (keycode == SYSRQ_KEY) {
-		sysrq_pressed = !up_flag;
-		goto out;
-	} else if (sysrq_pressed) {
-		if (!up_flag) {
-			handle_sysrq(kbd_sysrq_xlate[keycode], kbd_pt_regs, kbd, tty);
-			goto out;
+#ifdef CONFIG_MAGIC_SYSRQ               /* Handle the SysRq Hack */
+	/*
+	  Pressing magic + command key acts as a chorded command.
+	  Pressing and releasing magic without a command key acts sticky,
+	  using the next non-magic key as a command key
+	  Pressing magic twice without a command key passes the magic key
+	  through.
+	 */
+
+        if (sysrq_ctls.enabled) {
+		if (keycode == sysrq_ctls.keycode) switch(sysrq_state) {
+			case UP_AND_CLEAR:
+				sysrq_state = up_flag ? UP_AND_CLEAR :
+							DOWN_AND_WAITING;
+				/* consume the key event */
+				goto out;
+
+			case DOWN_AND_WAITING:
+				if (up_flag) {
+					if (sysrq_ctls.sticky) {
+						sysrq_state = UP_AND_WAITING;
+					} else {
+						sysrq_state = UP_AND_CLEAR;
+					}
+				} else {
+					sysrq_state = DOWN_AND_WAITING;
+				}
+				/* consume the key event */
+				goto out;
+
+			case DOWN_AND_DONE:
+				sysrq_state = up_flag ? UP_AND_CLEAR :
+							DOWN_AND_DONE;
+				/* consume the key event */
+				goto out;
+
+			case DOWN_AND_PASS:
+			case UP_AND_WAITING:
+				sysrq_state = up_flag ? UP_AND_CLEAR :
+							DOWN_AND_PASS;
+				/* pass the key event through */
+				break;
+
+		} else switch(sysrq_state) {
+			case UP_AND_WAITING:
+			case DOWN_AND_WAITING:
+			case DOWN_AND_DONE:
+				if (!up_flag) {
+					handle_sysrq(kbd_sysrq_xlate[keycode],
+							kbd_pt_regs, kbd, tty);
+				}
+
+				if (sysrq_state == UP_AND_WAITING) {
+					sysrq_state = UP_AND_CLEAR;
+				} else {
+					sysrq_state = DOWN_AND_DONE;
+				}
+
+				/* consume the key event */
+				goto out;
+
+
+			case DOWN_AND_PASS:
+			case UP_AND_CLEAR:
+				/* pass the key event through */
+				break;
+
 		}
+        } else {
+		sysrq_state = UP_AND_CLEAR;
 	}
 #endif
 
diff -ur linux-2.4.11-pre2/drivers/char/sysrq.c linux-2.4.11-pre2-stateful_sysrq/drivers/char/sysrq.c
--- linux-2.4.11-pre2/drivers/char/sysrq.c	Mon Oct  1 23:13:36 2001
+++ linux-2.4.11-pre2-stateful_sysrq/drivers/char/sysrq.c	Wed Oct  3 09:55:42 2001
@@ -32,12 +32,24 @@
 
 #include <asm/ptrace.h>
 
+/* for the SYSRQ_KEY definition */
+#include <asm/keyboard.h>
+
 extern void reset_vc(unsigned int);
 extern struct list_head super_blocks;
 
 /* Whether we react on sysrq keys or just ignore them */
-int sysrq_enabled = 1;
+struct sysrq_ctls_struct sysrq_ctls = {
+	/* Whether we react on sysrq keys or just ignore them */
+	enabled: 1,
+
+	/* The keycode for the magic key, referred to as sysrq */
+	keycode: SYSRQ_KEY,
 
+	/* is the sysrq key 'sticky'? */
+	sticky: 0,
+};
+ 
 /* Machine specific power off function */
 void (*sysrq_power_off)(void);
 
@@ -231,7 +243,7 @@
 static void sysrq_handle_mountro(int key, struct pt_regs *pt_regs,
 		struct kbd_struct *kbd, struct tty_struct *tty) {
 	emergency_sync_scheduled = EMERG_REMOUNT;
-	wakeup_bdflush(0);
+	wakeup_bdflush();
 }
 static struct sysrq_key_op sysrq_mountro_op = {
 	handler:	sysrq_handle_mountro,
@@ -433,7 +445,7 @@
 
 void handle_sysrq(int key, struct pt_regs *pt_regs,
 		  struct kbd_struct *kbd, struct tty_struct *tty) {
-	if (!sysrq_enabled)
+	if (!sysrq_ctls.enabled)
 		return;
 
 	__sysrq_lock_table();
@@ -453,7 +465,7 @@
 	int orig_log_level;
 	int i, j;
 	
-	if (!sysrq_enabled)
+	if (!sysrq_ctls.enabled)
 		return;
 
 	orig_log_level = console_loglevel;
diff -ur linux-2.4.11-pre2/include/linux/sysctl.h linux-2.4.11-pre2-stateful_sysrq/include/linux/sysctl.h
--- linux-2.4.11-pre2/include/linux/sysctl.h	Mon Oct  1 23:13:44 2001
+++ linux-2.4.11-pre2-stateful_sysrq/include/linux/sysctl.h	Wed Oct  3 00:17:13 2001
@@ -106,7 +106,7 @@
 	KERN_MSGMAX=35,         /* int: Maximum size of a messege */
 	KERN_MSGMNB=36,         /* int: Maximum message queue size */
 	KERN_MSGPOOL=37,        /* int: Maximum system message pool size */
-	KERN_SYSRQ=38,		/* int: Sysreq enable */
+	KERN_SYSRQ=38,		/* struct: Sysreq enable, keycode, sticky */
 	KERN_MAX_THREADS=39,	/* int: Maximum nr of threads in the system */
  	KERN_RANDOM=40,		/* Random driver */
  	KERN_SHMALL=41,		/* int: Maximum size of shared memory */
diff -ur linux-2.4.11-pre2/include/linux/sysrq.h linux-2.4.11-pre2-stateful_sysrq/include/linux/sysrq.h
--- linux-2.4.11-pre2/include/linux/sysrq.h	Mon Oct  1 23:13:44 2001
+++ linux-2.4.11-pre2-stateful_sysrq/include/linux/sysrq.h	Wed Oct  3 00:15:26 2001
@@ -26,6 +26,13 @@
 
 #ifdef CONFIG_MAGIC_SYSRQ
 
+/*  sysrq_ctls - controls aspects of the SYSRQ magic key hack*/
+struct sysrq_ctls_struct {
+	int enabled;
+	int keycode;
+	int sticky;
+};
+
 /* Generic SysRq interface -- you may call it from any device driver, supplying
  * ASCII code of the key, pointer to registers and kbd/tty structs (if they
  * are available -- else NULL's).
diff -ur linux-2.4.11-pre2/kernel/sysctl.c linux-2.4.11-pre2-stateful_sysrq/kernel/sysctl.c
--- linux-2.4.11-pre2/kernel/sysctl.c	Mon Oct  1 23:13:44 2001
+++ linux-2.4.11-pre2-stateful_sysrq/kernel/sysctl.c	Wed Oct  3 00:18:43 2001
@@ -46,7 +46,7 @@
 extern int sysctl_overcommit_memory;
 extern int max_threads;
 extern int nr_queued_signals, max_queued_signals;
-extern int sysrq_enabled;
+extern struct sysrq_ctls_struct sysrq_ctls;
 extern int core_uses_pid;
 extern int cad_pid;
 
@@ -233,7 +233,11 @@
 	 0644, NULL, &proc_dointvec},
 #endif
 #ifdef CONFIG_MAGIC_SYSRQ
-	{KERN_SYSRQ, "sysrq", &sysrq_enabled, sizeof (int),
+	{KERN_SYSRQ, "sysrq", &sysrq_ctls.enabled, sizeof (int),
+	 0644, NULL, &proc_dointvec},
+	{KERN_SYSRQ, "sysrq-key", &sysrq_ctls.keycode, sizeof (sysrq_ctls.keycode),
+	 0644, NULL, &proc_dointvec},
+	{KERN_SYSRQ, "sysrq-sticky", &sysrq_ctls.sticky, sizeof (sysrq_ctls.sticky),
 	 0644, NULL, &proc_dointvec},
 #endif	 
 	{KERN_CADPID, "cad_pid", &cad_pid, sizeof (int),

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

end of thread, other threads:[~2001-10-03 14:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-10-02  8:48 [PATCH] Stateful Magic Sysrq Key willy tarreau
2001-10-02 14:18 ` Crutcher Dunnavant
2001-10-03 14:05   ` [PATCH] Stateful Magic Sysrq Key + Sticky Tag Crutcher Dunnavant
     [not found] <20011002185016.90E271F9BA@zion.rivenstone.net>
2001-10-03  4:23 ` [PATCH] Stateful Magic Sysrq Key Ian Stirling
  -- strict thread matches above, loose matches on Subject: below --
2001-10-02  3:44 Crutcher Dunnavant
2001-10-02  4:14 ` Simon Kirby
2001-10-02  7:02 ` Ian Stirling

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