[PATCH] SYSRQfix #2 to work with odd keyboards

From: Mike A. Harris (mharris@meteng.on.ca)
Date: Sun Feb 27 2000 - 09:51:46 EST


The first patch that I sent out the other day was not the one I
intended to. While the first patch does in fact work ok, it
catches the ALT key a bit, making the speaker beep at you until
you switch VC's back and forth. I had fixed that and produced a
second patch, but accidentally included the wrong patch the first
time around. Duh. ;o(

Please apply this patch to 2.2.14, and any other kernel you have
around that it patches cleanly to. It is a safe patch that
changes VERY little. It only adds 4 lines of real code to the
kernel, and a few printk's which I'm going to remove from the
next patch as everything seems to work fine now.

If SYSRQ works for you allready, then it should continue to work
for you after using my patch. It implements 2 SYSRQ "modes" of
operation (in only 4 lines of code). If your keyboard is not
broken, like mine is, then SYSRQ will work for you properly using
either mode 1, or mode 2. If your keyboard is broken (sends
make/break simultaneously when SYSRQ is pressed, and sends
nothing at all when SYSRQ is released), then mode 2 enables SYSRQ
to work on your broken keyboard as well. The patch does nothing
insane at all, and ONLY modifies code inside CONFIG_MAGIC_SYSRQ.

It also patches the Documentation/sysrq.txt document with info on
how to enable Sysrq (which was missing).

An example of such a broken keyboard is the M-Tek K208 keyboard.

echo 1 > /proc/sys/kernel/sysrq
        - gives the existing SYSRQ behavior UNMODIFIED

echo 2 > /proc/sys/kernel/sysrq
        - turns on my alternate mode, which allows broken
          keyboards to use SYSRQ too, while still allowing normal
          keyboards to continue to work with SYSRQ as well.

The result of mode 2, is that the SYSRQ key acts more like a
"sticky" key while either ALT key is being still held down.

Once again, I have tested the patch out on 2 different computers,
using two different keyboards (one normal, one broken), and every
permutation of sysrq "mode" from above. I've tried pressing
oddball key combinations in an effort to break my code, and all
attempts have been unsuccessful.

This code is rock solid, and safe enough to launch the space
shuttle with. Your bank uses it, and so should you. ;o)

Seriously, please test it out, and report any problems to me -
even though you won't have any.

Here is the relevant code from before and after my patch:

Before my patch (2.2.14):

#ifdef CONFIG_MAGIC_SYSRQ /* Handle the SysRq Hack */
        if (keycode == SYSRQ_KEY) {
                sysrq_pressed = !up_flag;
                return;
        } else if (sysrq_pressed) {
                if (!up_flag && sysrq_enabled)
                        handle_sysrq(kbd_sysrq_xlate[keycode], kbd_pt_regs, kbd, tty);
                return;
        }
#endif

After my patch (2.2.14):

#ifdef CONFIG_MAGIC_SYSRQ /* Handle the SysRq Hack */
        /*
         * Some broken keyboards such as the Mtek K208 send both the
         * make and break scancodes for the SYSRQ key simultaneously
         * when the key is pressed down, and nothing when it is released,
         * thus preventing SYSRQ from working on such a keyboard.
         * If sysrq_enabled is set to "2" via /proc, the SYSRQ break
         * code is ignored, and the ALT key's break code is used in place
         * of it. - Mike A. Harris <mharris@meteng.on.ca>
         */

        if (keycode == SYSRQ_KEY) {
                if(sysrq_enabled == 1 || (sysrq_enabled == 2 && !sysrq_pressed) ) {
                        sysrq_pressed = !up_flag;
                        printk(KERN_DEBUG "keyboard.c: L1 SE=%d SP=%04x keycode=%02x up_flag=%02x\n",
                            sysrq_enabled, sysrq_pressed, keycode, up_flag);
                }
                return;
#define ALT_BREAK 0xb8
        } else if (sysrq_enabled == 2 && sysrq_pressed && scancode == ALT_BREAK) {
                sysrq_pressed = !up_flag;
                        printk(KERN_DEBUG "keyboard.c: L2 SE=%d SP=%04x keycode=%02x up_flag=%02x\n",
                            sysrq_enabled, sysrq_pressed, keycode, up_flag);
        } else if (sysrq_pressed) {
                if (!up_flag && sysrq_enabled)
                        handle_sysrq(kbd_sysrq_xlate[keycode], kbd_pt_regs, kbd, tty);
                return;
        }
#endif

Assuming I don't receive any bug reports in the next few days,
I'll clean up the patch, remove printk()'s, etc...

Please feel free to comment on the patch however you see fit.
TTYL

-- 
Mike A. Harris                                     Linux advocate     
Computer Consultant                                  GNU advocate  
Capslock Consulting                          Open Source advocate

Suspicious Anagram #4: Word: PRESIDENT CLINTON OF THE USA Anagram: TO COPULATE HE FINDS INTERNS


- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Tue Feb 29 2000 - 21:00:17 EST