Skip to contentSkip to conversation

change SysRq keycode for systems without SysRq key

PATCH In review federico ferri 2 participants 3 messages Jul 13, 2007 – Jul 17, 2007

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

PATCH 1/1 change SysRq keycode for systems without SysRq key

this patch adds an entry in Kconfig after 'config MAGIC_SYSRQ' which asks for a different keycode (replacing also KEY_SYSRQ with CONFIG_MAGIC_SYSRQ_KEYCODE in char/keyboard.c)

it was tested on some USB keyboards (Microsoft and Apple USB keyboards, and it works)

I sumbitted this patch two years ago, but it was ignored.

I think this patch is very important, even to a non-developer (SysRq-k is very helpful when testing unstable software/drivers)

Signature · 1 line
federico ferri
drivers/char/keyboard.c +1 -1
diff -uprN linux.orig/drivers/char/keyboard.c linux/drivers/char/keyboard.c
@@ -1081,7 +1087,7 @@ static void kbd_keycode(unsigned int key
 				printk(KERN_WARNING "keyboard.c: can't emulate rawmode for keycode %d\n", keycode);
 
 #ifdef CONFIG_MAGIC_SYSRQ	       /* Handle the SysRq Hack */
-	if (keycode == KEY_SYSRQ && (sysrq_down || (down == 1 && sysrq_alt))) {
+	if (keycode == CONFIG_MAGIC_SYSRQ_KEYCODE && (sysrq_down || (down == 1 && sysrq_alt))) {
 		sysrq_down = down;
 		return;
 	}
lib/Kconfig.debug +12 -0
diff -uprN linux.orig/lib/Kconfig.debug linux/lib/Kconfig.debug
@@ -28,6 +28,16 @@ config MAGIC_SYSRQ
 	  send a BREAK and then within 5 seconds a command keypress. The
 	  keys are documented in <file:Documentation/sysrq.txt>. Don't say Y
 	  unless you really know what this hack does.
+	  
+config MAGIC_SYSRQ_KEYCODE
+	int
+	prompt "Change SysRq key-code" if MAGIC_SYSRQ
+	default 99
+	depends on MAGIC_SYSRQ
+	help
+	  If your keyboard doesn't have a SysRq key (also labeled PrintScr),
+	  you can specify another keycode which should act as SysRq.
+	  Default is 99 (KEY_SYSRQ).
+	  You can find this number using programs like evtest, or (maybe)
+	  showkey.
 

config LOG_BUF_SHIFT
int "Kernel log buffer size (16 => 64KB, 17 => 128KB)" if DEBUG_KERNEL

maintainer
#1 lore raw
Quoted 16 lines · On Fri, 13 Jul 2007 23:20:33 +0200 federico ferri <[email protected]> wrote:

#ifdef CONFIG_MAGIC_SYSRQ /* Handle the SysRq Hack */

drivers/char/keyboard.c +1 -1
-	if (keycode == KEY_SYSRQ && (sysrq_down || (down == 1 && sysrq_alt))) {
+	if (keycode == CONFIG_MAGIC_SYSRQ_KEYCODE && (sysrq_down || (down == 1 && sysrq_alt))) {
 		sysrq_down = down;
 		return;
 	}

diff -uprN linux.orig/lib/Kconfig.debug linux/lib/Kconfig.debug

lib/Kconfig.debug +3 -0
@@ -28,6 +28,16 @@ config MAGIC_SYSRQ
 	  send a BREAK and then within 5 seconds a command keypress. The
 	  keys are documented in <file:Documentation/sysrq.txt>. Don't say Y
 	  unless you really know what this hack does.
+	  
+config MAGIC_SYSRQ_KEYCODE
+	int

lib/Kconfig.debug config MAGIC_SYSRQ · line 43

Quoted 10 lines
lib/Kconfig.debug +9 -0
+	prompt "Change SysRq key-code" if MAGIC_SYSRQ
+	default 99
+	depends on MAGIC_SYSRQ
+	help
+	  If your keyboard doesn't have a SysRq key (also labeled PrintScr),
+	  you can specify another keycode which should act as SysRq.
+	  Default is 99 (KEY_SYSRQ).
+	  You can find this number using programs like evtest, or (maybe)
+	  showkey.
 

Seems harmless enough ;)

Could you please send in a suitable update to Documentation/sysrq.txt?

#2 lore raw

Andrew Morton ha scritto:

Quoted 3 lines

Seems harmless enough ;)

Could you please send in a suitable update to Documentation/sysrq.txt?

sorry, I should have written a few lines here...
issue solved (sorry for not CCing here, I'm shy ((: ) resulting in no need for a patch, just the need of a recent kernel and a userspace program.

I report here the full discussion I had with Linus Torvalds, Dmitry Torokhov (CCed to linux-input list):

Quoted 52 lines
Quoted 46 lines
Quoted 10 lines
Quoted 10 lines
Quoted 5 lines

this patch adds an entry in Kconfig after 'config MAGIC_SYSRQ' which asks for a different keycode (replacing also KEY_SYSRQ with CONFIG_MAGIC_SYSRQ_KEYCODE in char/keyboard.c)

Federico

Quite frankly, I think that if we want to make something like this configurable, it should be dynamic, not compiled-in. So that the same kernel image can be used with different keyboards.

Quoted 8 lines
Quoted 1 line

Linus

(I can imagine it could be done via a /proc/sysrq-keycode virtual file, but that's just one possibility)

So, this should turn into a feature request...
would you accept feature requests? ( :

Federico

Well, this is totally untested, and I won't guarantee that this works at all, but this is how to generally do these kinds of things..

Linus

---
 drivers/char/keyboard.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
drivers/char/keyboard.c +3 -0
index 90965b4..e21f52b 100644
@@ -157,6 +157,10 @@ static int sysrq_alt_use;
 #endif
 static int sysrq_alt;
 >> +static int sysrq_key = KEY_SYSRQ;
+module_param_named(sysrq_key, sysrq_key, uint, 0644);
+MODULE_PARM_DESC(sysrq_key, "The keycode to be used for sysrq");
+
 /*
  * Translation of scancodes to keycodes. We set them on only the first
  * keyboard in the list that accepts the scancode and keycode.
@@ -1139,7 +1143,7 @@ static void kbd_keycode(unsigned int keycode, int down, int hw_raw)
                 printk(KERN_WARNING "keyboard.c: can't emulate rawmode for keycode %d\n", keycode);
Quoted 1 line
Quoted 1 line

#ifdef CONFIG_MAGIC_SYSRQ /* Handle the SysRq Hack */

drivers/char/keyboard.c

Quoted 5 lines
drivers/char/keyboard.c +1 -1
-    if (keycode == KEY_SYSRQ && (sysrq_down || (down == 1 && sysrq_alt))) {
+    if (keycode == sysrq_key && (sysrq_down || (down == 1 && sysrq_alt))) {
         if (!sysrq_down) {
             sysrq_down = down;
             sysrq_alt_use = sysrq_alt;
Quoted 5 lines

YAY! it works great.
tried with:

# echo 183 > /sys/module/keyboard/parameters/sysrq_key
but also keyboard.sys_rq=183 on the command line should work; I'll
discover that on next reboot.

Yes, please do verify.

Quoted 1 line

thank you, Linus!

You're welcome.

Quoted 2 lines

(now that this has done in the proper way, is this patch going to be merged in the tree?)

I'm certainly ok with it, but I guess it's more up to Dmitry. If he ack's it, I can just commit it.

Dmitry? Any reason not to do this?

Linus

-------------------------------------------------------------------------------

Quoted 15 lines · federico ferri

Dmitry Torokhov ha scritto:

Quoted 9 lines
Quoted 2 lines

Dmitry? Any reason not to do this?

Recent kernels have the ability to remap keymap for USB keyboards via EVIOCSKEYCODE ioctl (we allowed 0adjusting keymaps on PS/2 keyboards for a long time). So instead of having the new parameter redefining SysRq keycode Frederico can remap one of the keys on his keyboard to generate KEY_SYSRQ. This way SysRq should still work if he plugs in another USB keyboard that has SysRq key or a PS/2 keyboard.

would setkeycodes still just work for PS2 keyboards?
I upgraded to newer kbd-1.13 package (kernel 2.6.21), and while trying to change sysrq keycode still I get the old error:

Quoted 9 lines

KDSETKEYCODE: No such device
failed to set scancode 38b7 to keycode 84

which I reported on gentoo a long time ago:
http://bugs.gentoo.org/show_bug.cgi?id=97388

(it doesn't use EVIOCSKEYCODE)
maybe I'm not picking up the right program?

EVIOCSKEYCODE support for HID (USB) went in in 2.6.22-rc1.

There is keyfuzz utility you can use to play with keymaps for a particular device:

http://0pointer.de/lennart/projects/keyfuzz/

Signature · 1 line
Dmitry