Creating a ``Magic Button''

Artem Ignatiev timon at memphis.mephi.ru
Mon Feb 23 12:12:05 PST 2004


Hello, hackers

Friend of mine, who's using linux, showed me once this kind of things:
``When I'm too bored to do shutdown, I use Alt-SysRq button.
Sync-Sync-Sync, remount all fs to r/o, halt'' - or something like that.

I thought that this will be useful feature - when system is almost dead,
but syscons's still alive (and you have no debugger in kernel) try to
minimize loss of data trying to sync your disks, and doing halt.

Adding ``SYNC'' button to syscons & kbdcontrol went fine, but then I
wished to make an accented keys, with all these neat things. I've found
that kbdcontrol don't allows me to use dead keys for entering other,
than just plain ascii symbols. So I wished to change kbdcontrol a little
bit more, to allow entering keys like ``pdwn'' from accents. So - the
last thing to do is to change definition of accentmap_t like this:

--- /sys/sys/kbio.h     Mon Feb 23 22:24:24 2004
+++ kbio.h      Mon Feb 23 23:07:01 2004
@@ -179,13 +179,13 @@
 #define F(x)           ((x)+F_FN-1)
 #define        S(x)            ((x)+F_SCR-1)
 #define ACC(x)         ((x)+F_ACC)
 
 struct acc_t {
        u_char          accchar;
-       u_char          map[NUM_ACCENTCHARS][2];
+       u_short         map[NUM_ACCENTCHARS][2];
 };
 
 struct accentmap {
        u_short         n_accs;
        struct acc_t    acc[NUM_DEADKEYS];
 };

but immediately after applying this patch, PIO_DEADKEYMAP suddenly
disappeared (kbdcontrol gets ENOTTY "Inappopriate ioctl for device" when
trying to set accentmap). 
I can't find out, what and where depends on acc_t. What am i missing?

Below is the patch of ``what i've done already'', it still lacks some
bits, like accurate dump of accents definitions.

-------------- next part --------------
--- ./sys/dev/kbd/kbd.c.orig	Sun Jan 25 03:48:55 2004
+++ ./sys/dev/kbd/kbd.c	Mon Feb 23 16:29:13 2004
@@ -1280,7 +1280,7 @@
 			/* NON-LOCKING KEYS */
 			case SPSC: case RBT:  case SUSP: case STBY:
 			case DBG:  case NEXT: case PREV: case PNC:
-			case HALT: case PDWN:
+			case HALT: case PDWN: case SYNC:
 				*accents = 0;
 				break;
 			case BTAB:
--- ./sys/dev/syscons/syscons.c.orig	Sun Jan 25 04:02:07 2004
+++ ./sys/dev/syscons/syscons.c	Mon Feb 23 16:57:39 2004
@@ -50,6 +50,7 @@
 #include <sys/reboot.h>
 #include <sys/signalvar.h>
 #include <sys/sysctl.h>
+#include <sys/sysproto.h>
 #include <sys/tty.h>
 #include <sys/power.h>
 
@@ -3355,6 +3356,10 @@
 	    case PNC:
 		if (enable_panic_key)
 			panic("Forced by the panic key");
+		break;
+	    case SYNC: 
+		printf("Syncing disks\n");
+		sync(&thread0, NULL);
 		break;
 
 	    case NEXT:
--- ./sys/sys/kbio.h.orig	Sun Jan 25 03:55:12 2004
+++ ./sys/sys/kbio.h	Mon Feb 23 22:24:24 2004
@@ -174,6 +174,7 @@
 #define HALT		0xa1		/* halt machine */
 #define PDWN		0xa2		/* halt machine and power down */
 #define PASTE		0xa3		/* paste from cut-paste buffer */
+#define SYNC		0xa4		/* force sync filesystems */
 
 #define F(x)		((x)+F_FN-1)
 #define	S(x)		((x)+F_SCR-1)
--- ./usr.sbin/kbdcontrol/lex.l.orig	Sun Jan 25 04:15:46 2004
+++ ./usr.sbin/kbdcontrol/lex.l	Sun Jan 25 04:16:01 2004
@@ -72,6 +72,7 @@
 halt		{ return THALT; }
 pdwn		{ return TPDWN; }
 paste		{ return TPASTE; }
+sync		{ return TSYNC; }
 
 NUL|nul		{ number = 0; return TNUM; }
 SOH|soh		{ number = 1; return TNUM; }
--- ./usr.sbin/kbdcontrol/lex.h.orig	Sun Jan 25 04:16:23 2004
+++ ./usr.sbin/kbdcontrol/lex.h	Sun Jan 25 04:16:48 2004
@@ -64,6 +64,7 @@
 #define THALT		289
 #define TPDWN		290
 #define TPASTE		291
+#define TSYNC		292
 
 extern int number;
 extern char letter;
--- ./usr.sbin/kbdcontrol/kbdcontrol.c.orig	Sun Jan 25 04:17:01 2004
+++ ./usr.sbin/kbdcontrol/kbdcontrol.c	Mon Feb 23 22:12:07 2004
@@ -238,6 +238,8 @@
 		return PDWN | 0x100;
 	case TPASTE:
 		return PASTE | 0x100;
+	case TSYNC:
+		return SYNC | 0x100;
 	case TACC:
 		if (ACC(number) > L_ACC)
 			return -1;
@@ -360,6 +362,39 @@
 			return -1;
 		}
 		switch ((token = yylex())) {
+		case TNEXT:
+			c2 = NEXT | SPCLKEY;
+			break;
+		case TPREV:
+			c2 = PREV | SPCLKEY;
+			break;
+		case TRBT:
+			c2 = RBT | SPCLKEY;
+			break;
+		case TDBG:
+			c2 = DBG | SPCLKEY;
+			break;
+		case TSUSP:
+			c2 = SUSP | SPCLKEY;
+			break;
+		case TSPSC:
+			c2 = SPSC | SPCLKEY;
+			break;
+		case TPANIC:
+			c2 = PNC | SPCLKEY;
+			break;
+		case THALT:
+			c2 = HALT | SPCLKEY;
+			break;
+		case TPDWN:
+			c2 = PDWN | SPCLKEY;
+			break;
+		case TPASTE:
+			c2 = PASTE | SPCLKEY;
+			break;
+		case TSYNC:
+			c2 = SYNC | SPCLKEY;
+			break;
 		case TLET:
 			c2 = letter;
 			break;
@@ -451,6 +486,9 @@
 	case PNC | 0x100:
 		fprintf(fp, " panic ");
 		break;
+	case SYNC | 0x100:
+		fprintf(fp, " sync  ");
+		break;
 	case LSHA | 0x100:
 		fprintf(fp, " lshifta");
 		break;
--- share/syscons/keymaps/ru.koi8-r.kbd	Mon Apr  9 20:36:48 2001
+++ /usr/share/syscons/keymaps/ru.koi8-r.timon.kbd	Mon Feb 23 16:38:46 2004
@@ -4,7 +4,7 @@
 # code  base   shift  cntrl  shift  alt    shift  cntrl  shift state
 # ------------------------------------------------------------------
   000   nop    nop    nop    nop    nop    nop    nop    nop     O
-  001   esc    esc    nop    nop    155    155    debug  nop     O
+  001   esc    esc    dogo   nop    155    155    debug  nop     O
   002   '1'    '!'    nop    nop    177    161    nop    nop     O
   003   '2'    '@'    nul    nul    178    192    128    128     O
   004   '3'    '#'    nop    nop    179    163    nop    nop     O
@@ -132,7 +132,7 @@
   126   nop    nop    nop    nop    nop    nop    nop    nop     O
   127   nop    nop    nop    nop    nop    nop    nop    nop     O
   128   nop    nop    nop    nop    nop    nop    nop    nop     O
-  129   esc    esc    nop    nop    155    155    debug  nop     O
+  129   esc    esc    dogo   nop    155    155    debug  nop     O
   130   '!'    '1'    nop    nop    177    161    nop    nop     O
   131   '"'    '2'    nul    nul    178    192    128    128     O
   132   '''    '3'    nop    nop    179    163    nop    nop     O
@@ -240,3 +240,5 @@
   234   fkey63 fkey63 fkey63 fkey63 fkey63 fkey63 fkey63 fkey63  O
   235   fkey64 fkey64 fkey64 fkey64 fkey64 fkey64 fkey64 fkey64  O
   236   nop    nop    nop    nop    nop    nop    nop    nop     O
+dogo 001 ( 'd' debug ) ( 'h' halt ) ( 'p' pdwn ) ( 's' sync ) ( 'P' panic )
+#dogo 001 ( 'd' 32) ( 'h' 33) ('p' 34) ( 's' 35) ('P' 36)


More information about the freebsd-hackers mailing list