aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--console-tools/kbd_mode.c22
-rw-r--r--libbb/get_console.c1
2 files changed, 14 insertions, 9 deletions
diff --git a/console-tools/kbd_mode.c b/console-tools/kbd_mode.c
index da31af28d..b0b594614 100644
--- a/console-tools/kbd_mode.c
+++ b/console-tools/kbd_mode.c
@@ -22,7 +22,7 @@
22//usage:#define kbd_mode_trivial_usage 22//usage:#define kbd_mode_trivial_usage
23//usage: "[-a|k|s|u] [-C TTY]" 23//usage: "[-a|k|s|u] [-C TTY]"
24//usage:#define kbd_mode_full_usage "\n\n" 24//usage:#define kbd_mode_full_usage "\n\n"
25//usage: "Report or set the keyboard mode\n" 25//usage: "Report or set VT console keyboard mode\n"
26//usage: "\n -a Default (ASCII)" 26//usage: "\n -a Default (ASCII)"
27//usage: "\n -k Medium-raw (keycode)" 27//usage: "\n -k Medium-raw (keycode)"
28//usage: "\n -s Raw (scancode)" 28//usage: "\n -s Raw (scancode)"
@@ -43,15 +43,20 @@ int kbd_mode_main(int argc UNUSED_PARAM, char **argv)
43 }; 43 };
44 int fd; 44 int fd;
45 unsigned opt; 45 unsigned opt;
46//TODO? kbd-2.0.3 without -C tries in sequence: 46 const char *tty_name;
47//fd#0, /dev/tty, /dev/tty0.
48//Also, it checks KDGKBTYPE before doing KDGKBMODE
49//maybe we can use get_console_fd_or_die()?
50 const char *tty_name = CURRENT_TTY;
51 47
52 opt = getopt32(argv, "sakuC:", &tty_name); 48 opt = getopt32(argv, "sakuC:", &tty_name);
53 fd = xopen_nonblocking(tty_name); 49 if (opt & 0x10) {
54 opt &= 0xf; /* clear -C bit, see (*) */ 50 opt &= 0xf; /* clear -C bit, see (*) */
51 fd = xopen_nonblocking(tty_name);
52 } else {
53 /* kbd-2.0.3 tries in sequence:
54 * fd#0, /dev/tty, /dev/tty0.
55 * get_console_fd_or_die: /dev/console, /dev/tty0, /dev/tty.
56 * kbd-2.0.3 checks KDGKBTYPE, get_console_fd_or_die checks too.
57 */
58 fd = get_console_fd_or_die();
59 }
55 60
56 if (!opt) { /* print current setting */ 61 if (!opt) { /* print current setting */
57 const char *mode = "unknown"; 62 const char *mode = "unknown";
@@ -79,6 +84,7 @@ int kbd_mode_main(int argc UNUSED_PARAM, char **argv)
79 * #define K_OFF 0x04 84 * #define K_OFF 0x04
80 * (looks like "-ak" together would cause the same effect as -u) 85 * (looks like "-ak" together would cause the same effect as -u)
81 */ 86 */
87 opt &= 0xf; /* clear -C bit */
82 opt = opt & UNICODE ? 3 : opt >> 1; 88 opt = opt & UNICODE ? 3 : opt >> 1;
83 /* double cast prevents warnings about widening conversion */ 89 /* double cast prevents warnings about widening conversion */
84 xioctl(fd, KDSKBMODE, (void*)(ptrdiff_t)opt); 90 xioctl(fd, KDSKBMODE, (void*)(ptrdiff_t)opt);
diff --git a/libbb/get_console.c b/libbb/get_console.c
index 9b6407bd0..96b339ca7 100644
--- a/libbb/get_console.c
+++ b/libbb/get_console.c
@@ -64,7 +64,6 @@ int FAST_FUNC get_console_fd_or_die(void)
64 } 64 }
65 65
66 bb_error_msg_and_die("can't open console"); 66 bb_error_msg_and_die("can't open console");
67 /*return fd; - total failure */
68} 67}
69 68
70/* From <linux/vt.h> */ 69/* From <linux/vt.h> */