Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ctrlchar.c
Go to the documentation of this file.
1 /*
2  * Unified handling of special chars.
3  *
4  * Copyright IBM Corp. 2001
5  * Author(s): Fritz Elfert <[email protected]> <[email protected]>
6  *
7  */
8 
9 #include <linux/stddef.h>
10 #include <asm/errno.h>
11 #include <linux/sysrq.h>
12 #include <linux/ctype.h>
13 
14 #include "ctrlchar.h"
15 
16 #ifdef CONFIG_MAGIC_SYSRQ
17 static int ctrlchar_sysrq_key;
18 
19 static void
20 ctrlchar_handle_sysrq(struct work_struct *work)
21 {
22  handle_sysrq(ctrlchar_sysrq_key);
23 }
24 
25 static DECLARE_WORK(ctrlchar_work, ctrlchar_handle_sysrq);
26 #endif
27 
28 
40 unsigned int
41 ctrlchar_handle(const unsigned char *buf, int len, struct tty_struct *tty)
42 {
43  if ((len < 2) || (len > 3))
44  return CTRLCHAR_NONE;
45 
46  /* hat is 0xb1 in codepage 037 (US etc.) and thus */
47  /* converted to 0x5e in ascii ('^') */
48  if ((buf[0] != '^') && (buf[0] != '\252'))
49  return CTRLCHAR_NONE;
50 
51 #ifdef CONFIG_MAGIC_SYSRQ
52  /* racy */
53  if (len == 3 && buf[1] == '-') {
54  ctrlchar_sysrq_key = buf[2];
55  schedule_work(&ctrlchar_work);
56  return CTRLCHAR_SYSRQ;
57  }
58 #endif
59 
60  if (len != 2)
61  return CTRLCHAR_NONE;
62 
63  switch (tolower(buf[1])) {
64  case 'c':
65  return INTR_CHAR(tty) | CTRLCHAR_CTRL;
66  case 'd':
67  return EOF_CHAR(tty) | CTRLCHAR_CTRL;
68  case 'z':
69  return SUSP_CHAR(tty) | CTRLCHAR_CTRL;
70  }
71  return CTRLCHAR_NONE;
72 }