aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--console-tools/Config.in6
-rw-r--r--console-tools/Kbuild1
-rw-r--r--console-tools/kbd_mode.c71
-rw-r--r--include/applets.h1
-rw-r--r--include/usage.h10
-rw-r--r--libbb/get_console.c2
6 files changed, 90 insertions, 1 deletions
diff --git a/console-tools/Config.in b/console-tools/Config.in
index f82d4ce13..bd9dfb381 100644
--- a/console-tools/Config.in
+++ b/console-tools/Config.in
@@ -31,6 +31,12 @@ config DUMPKMAP
31 This program dumps the kernel's keyboard translation table to 31 This program dumps the kernel's keyboard translation table to
32 stdout, in binary format. You can then use loadkmap to load it. 32 stdout, in binary format. You can then use loadkmap to load it.
33 33
34config KBD_MODE
35 bool "kbd_mode"
36 default n
37 help
38 This program reports and sets keyboard mode.
39
34config LOADFONT 40config LOADFONT
35 bool "loadfont" 41 bool "loadfont"
36 default n 42 default n
diff --git a/console-tools/Kbuild b/console-tools/Kbuild
index a55bc087c..cf3825ec6 100644
--- a/console-tools/Kbuild
+++ b/console-tools/Kbuild
@@ -10,6 +10,7 @@ lib-$(CONFIG_CLEAR) += clear.o
10lib-$(CONFIG_DEALLOCVT) += deallocvt.o 10lib-$(CONFIG_DEALLOCVT) += deallocvt.o
11lib-$(CONFIG_DUMPKMAP) += dumpkmap.o 11lib-$(CONFIG_DUMPKMAP) += dumpkmap.o
12lib-$(CONFIG_SETCONSOLE) += setconsole.o 12lib-$(CONFIG_SETCONSOLE) += setconsole.o
13lib-$(CONFIG_KBD_MODE) += kbd_mode.o
13lib-$(CONFIG_LOADFONT) += loadfont.o 14lib-$(CONFIG_LOADFONT) += loadfont.o
14lib-$(CONFIG_LOADKMAP) += loadkmap.o 15lib-$(CONFIG_LOADKMAP) += loadkmap.o
15lib-$(CONFIG_OPENVT) += openvt.o 16lib-$(CONFIG_OPENVT) += openvt.o
diff --git a/console-tools/kbd_mode.c b/console-tools/kbd_mode.c
new file mode 100644
index 000000000..0000ea180
--- /dev/null
+++ b/console-tools/kbd_mode.c
@@ -0,0 +1,71 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Mini loadkmap implementation for busybox
4 *
5 * Copyright (C) 2007 Loïc Grenié <loic.grenie@gmail.com>
6 * written using Andries Brouwer <aeb@cwi.nl>'s kbd_mode from
7 * console-utils v0.2.3, licensed under GNU GPLv2
8 *
9 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
10 *
11 */
12
13#include <getopt.h>
14#include "libbb.h"
15#include <linux/kd.h>
16
17int kbd_mode_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
18int kbd_mode_main(int argc, char **argv)
19{
20 static const char opts[] = "saku";
21
22 const char *opt = argv[1];
23 const char *p;
24 int fd;
25
26 fd = get_console_fd();
27 if (fd < 0) /* get_console_fd() already complained */
28 return EXIT_FAILURE;
29
30 if (opt == NULL) {
31 /* No arg */
32 const char *msg = "unknown";
33 int mode;
34
35 ioctl(fd, KDGKBMODE, &mode);
36 switch(mode) {
37 case K_RAW:
38 msg = "raw (scancode)";
39 break;
40 case K_XLATE:
41 msg = "default (ASCII)";
42 break;
43 case K_MEDIUMRAW:
44 msg = "mediumraw (keycode)";
45 break;
46 case K_UNICODE:
47 msg = "Unicode (UTF-8)";
48 break;
49 }
50 printf("The keyboard is in %s mode\n", msg);
51 }
52 else if (argc > 2 /* more than 1 arg */
53 || *opt != '-' /* not an option */
54 || (p = strchr(opts, opt[1])) == NULL /* not an option we expect */
55 || opt[2] != '\0' /* more than one option char */
56 ) {
57 bb_show_usage();
58 /* return EXIT_FAILURE; - not reached */
59 }
60 else {
61#if K_RAW != 0 || K_XLATE != 1 || K_MEDIUMRAW != 2 || K_UNICODE != 3
62#error kbd_mode must be changed
63#endif
64 /* The options are in the order of the various K_xxx */
65 ioctl(fd, KDSKBMODE, p - opts);
66 }
67
68 if (ENABLE_FEATURE_CLEAN_UP)
69 close(fd);
70 return EXIT_SUCCESS;
71}
diff --git a/include/applets.h b/include/applets.h
index 5b64e3a5a..587ccbf51 100644
--- a/include/applets.h
+++ b/include/applets.h
@@ -202,6 +202,7 @@ USE_IPLINK(APPLET(iplink, _BB_DIR_BIN, _BB_SUID_NEVER))
202USE_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_NEVER)) 202USE_IPROUTE(APPLET(iproute, _BB_DIR_BIN, _BB_SUID_NEVER))
203USE_IPRULE(APPLET(iprule, _BB_DIR_BIN, _BB_SUID_NEVER)) 203USE_IPRULE(APPLET(iprule, _BB_DIR_BIN, _BB_SUID_NEVER))
204USE_IPTUNNEL(APPLET(iptunnel, _BB_DIR_BIN, _BB_SUID_NEVER)) 204USE_IPTUNNEL(APPLET(iptunnel, _BB_DIR_BIN, _BB_SUID_NEVER))
205USE_KBD_MODE(APPLET(kbd_mode, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
205USE_KILL(APPLET(kill, _BB_DIR_BIN, _BB_SUID_NEVER)) 206USE_KILL(APPLET(kill, _BB_DIR_BIN, _BB_SUID_NEVER))
206USE_KILLALL(APPLET_ODDNAME(killall, kill, _BB_DIR_USR_BIN, _BB_SUID_NEVER, killall)) 207USE_KILLALL(APPLET_ODDNAME(killall, kill, _BB_DIR_USR_BIN, _BB_SUID_NEVER, killall))
207USE_KILLALL5(APPLET_ODDNAME(killall5, kill, _BB_DIR_USR_BIN, _BB_SUID_NEVER, killall5)) 208USE_KILLALL5(APPLET_ODDNAME(killall5, kill, _BB_DIR_USR_BIN, _BB_SUID_NEVER, killall5))
diff --git a/include/usage.h b/include/usage.h
index d9a6ae729..8f0a13c32 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -1805,6 +1805,16 @@
1805 " [[i|o]seq] [[i|o]key KEY] [[i|o]csum]\n" \ 1805 " [[i|o]seq] [[i|o]key KEY] [[i|o]csum]\n" \
1806 " [ttl TTL] [tos TOS] [[no]pmtudisc] [dev PHYS_DEV]" 1806 " [ttl TTL] [tos TOS] [[no]pmtudisc] [dev PHYS_DEV]"
1807 1807
1808#define kbd_mode_trivial_usage \
1809 "[-a|k|s|u]"
1810#define kbd_mode_full_usage \
1811 "Report or set the keyboard mode" \
1812 "\n\nOptions set mode:\n" \
1813 " -a Default (ASCII)\n" \
1814 " -k Medium-raw (keyboard)\n" \
1815 " -s Raw (scancode)\n" \
1816 " -u Unicode (utf-8)"
1817
1808#define kill_trivial_usage \ 1818#define kill_trivial_usage \
1809 "[-l] [-signal] process-id [process-id ...]" 1819 "[-l] [-signal] process-id [process-id ...]"
1810#define kill_full_usage \ 1820#define kill_full_usage \
diff --git a/libbb/get_console.c b/libbb/get_console.c
index b12951823..0da27b1e2 100644
--- a/libbb/get_console.c
+++ b/libbb/get_console.c
@@ -67,6 +67,6 @@ int get_console_fd(void)
67 } 67 }
68 } 68 }
69 69
70 bb_error_msg("cannot get file descriptor referring to console"); 70 bb_error_msg("can't open console");
71 return fd; /* total failure */ 71 return fd; /* total failure */
72} 72}