Stateful Magic Sysrq Key
Subsystems (3)
PATCH 1/1 Stateful Magic Sysrq Key
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
Signature · 3 lines
Crutcher <[email protected]> GCS d--- s+:>+:- a-- C++++$ UL++++$ L+++$>++++ !E PS+++ PE Y+ PGP+>++++ R-(+++) !tv(+++) b+(++++) G+ e>++++ h+>++ r* y+>*$
kernel/sysctl.c renamed from kernel/sysctl.c.stateful_sysrq +4 -2
@@ -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),
include/linux/sysctl.h renamed from include/linux/sysctl.h.stateful_sysrq +1 -1
@@ -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 */
include/linux/sysrq.h renamed from include/linux/sysrq.h.stateful_sysrq +6 -0
@@ -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).
drivers/char/keyboard.c renamed from drivers/char/keyboard.c.stateful_sysrq +76 -9
104 lines not on this page · raw message
drivers/char/sysrq.c renamed from drivers/char/sysrq.c.stateful_sysrq +12 -3
@@ -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;
kernel/sysctl.c renamed from kernel/sysctl.c.stateful_sysrq +4 -2
@@ -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),
include/linux/sysctl.h renamed from include/linux/sysctl.h.stateful_sysrq +1 -1
@@ -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 */
include/linux/sysrq.h renamed from include/linux/sysrq.h.stateful_sysrq +6 -0
@@ -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).
drivers/char/keyboard.c renamed from drivers/char/keyboard.c.stateful_sysrq +76 -9
104 lines not on this page · raw message
drivers/char/sysrq.c renamed from drivers/char/sysrq.c.stateful_sysrq +12 -3
@@ -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;
Quoted 5 lines · Crutcher Dunnavant
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. ]
[ [email protected] ][ [email protected] ]
[ Opinions expressed are not necessarily those of my employers. ]
Quoted 2 lines
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.