diff options
author | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2008-05-19 08:18:50 +0000 |
---|---|---|
committer | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2008-05-19 08:18:50 +0000 |
commit | ae4342ca3e30f7b11732ecda3ad15821e81bc314 (patch) | |
tree | 1878104940eac4649bc8add4d0b2893ab1cb0a94 /console-tools | |
parent | ee56e013cfb6304f66129afee7978b0864699419 (diff) | |
download | busybox-w32-ae4342ca3e30f7b11732ecda3ad15821e81bc314.tar.gz busybox-w32-ae4342ca3e30f7b11732ecda3ad15821e81bc314.tar.bz2 busybox-w32-ae4342ca3e30f7b11732ecda3ad15821e81bc314.zip |
- Rename getpty() to xgetpty() and adjust callers.
- Rewrite kbd_mode and setconsole
- Introduce and use console_make_active() and xopen_xwrite_close()
- honour buffer-reservation method as set by the user (dumpkmap, loadkmap)
- shrink rtcwake and some console-tools
Saves about 270 Bytes
Diffstat (limited to 'console-tools')
-rw-r--r-- | console-tools/chvt.c | 12 | ||||
-rw-r--r-- | console-tools/dumpkmap.c | 19 | ||||
-rw-r--r-- | console-tools/kbd_mode.c | 73 | ||||
-rw-r--r-- | console-tools/loadkmap.c | 25 | ||||
-rw-r--r-- | console-tools/openvt.c | 23 | ||||
-rw-r--r-- | console-tools/reset.c | 2 | ||||
-rw-r--r-- | console-tools/setconsole.c | 32 | ||||
-rw-r--r-- | console-tools/setlogcons.c | 9 |
8 files changed, 85 insertions, 110 deletions
diff --git a/console-tools/chvt.c b/console-tools/chvt.c index ea96d1360..ea3e7c048 100644 --- a/console-tools/chvt.c +++ b/console-tools/chvt.c | |||
@@ -9,25 +9,17 @@ | |||
9 | 9 | ||
10 | #include "libbb.h" | 10 | #include "libbb.h" |
11 | 11 | ||
12 | /* From <linux/vt.h> */ | ||
13 | enum { | ||
14 | VT_ACTIVATE = 0x5606, /* make vt active */ | ||
15 | VT_WAITACTIVE = 0x5607 /* wait for vt active */ | ||
16 | }; | ||
17 | |||
18 | int chvt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 12 | int chvt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
19 | int chvt_main(int argc, char **argv) | 13 | int chvt_main(int argc, char **argv) |
20 | { | 14 | { |
21 | int fd, num; | 15 | int num; |
22 | 16 | ||
23 | if (argc != 2) { | 17 | if (argc != 2) { |
24 | bb_show_usage(); | 18 | bb_show_usage(); |
25 | } | 19 | } |
26 | 20 | ||
27 | fd = get_console_fd(); | ||
28 | num = xatou_range(argv[1], 1, 63); | 21 | num = xatou_range(argv[1], 1, 63); |
29 | /* double cast suppresses "cast to ptr from int of different size" */ | 22 | /* double cast suppresses "cast to ptr from int of different size" */ |
30 | xioctl(fd, VT_ACTIVATE, (void *)(ptrdiff_t)num); | 23 | console_make_active(get_console_fd(), num); |
31 | xioctl(fd, VT_WAITACTIVE, (void *)(ptrdiff_t)num); | ||
32 | return EXIT_SUCCESS; | 24 | return EXIT_SUCCESS; |
33 | } | 25 | } |
diff --git a/console-tools/dumpkmap.c b/console-tools/dumpkmap.c index 40b58f716..1adfdd738 100644 --- a/console-tools/dumpkmap.c +++ b/console-tools/dumpkmap.c | |||
@@ -7,6 +7,7 @@ | |||
7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
8 | * | 8 | * |
9 | */ | 9 | */ |
10 | /* no options, no getopt */ | ||
10 | 11 | ||
11 | #include "libbb.h" | 12 | #include "libbb.h" |
12 | 13 | ||
@@ -23,18 +24,17 @@ struct kbentry { | |||
23 | #define MAX_NR_KEYMAPS 256 | 24 | #define MAX_NR_KEYMAPS 256 |
24 | 25 | ||
25 | int dumpkmap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 26 | int dumpkmap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
26 | int dumpkmap_main(int argc, char **argv) | 27 | int dumpkmap_main(int ATTRIBUTE_UNUSED argc, char ATTRIBUTE_UNUSED **argv) |
27 | { | 28 | { |
28 | struct kbentry ke; | 29 | struct kbentry ke; |
29 | int i, j, fd; | 30 | int i, j, fd; |
30 | char flags[MAX_NR_KEYMAPS]; | 31 | RESERVE_CONFIG_BUFFER(flags,MAX_NR_KEYMAPS); |
31 | 32 | ||
32 | if (argc >= 2 && argv[1][0] == '-') | 33 | /* bb_warn_ignoring_args(argc>=2);*/ |
33 | bb_show_usage(); | ||
34 | 34 | ||
35 | fd = xopen(CURRENT_VC, O_RDWR); | 35 | fd = xopen(CURRENT_VC, O_RDWR); |
36 | 36 | ||
37 | write(1, "bkeymap", 7); | 37 | write(STDOUT_FILENO, "bkeymap", 7); |
38 | 38 | ||
39 | /* Here we want to set everything to 0 except for indexes: | 39 | /* Here we want to set everything to 0 except for indexes: |
40 | * [0-2] [4-6] [8-10] [12] */ | 40 | * [0-2] [4-6] [8-10] [12] */ |
@@ -43,7 +43,7 @@ int dumpkmap_main(int argc, char **argv) | |||
43 | flags[3] = flags[7] = flags[11] = 0; | 43 | flags[3] = flags[7] = flags[11] = 0; |
44 | 44 | ||
45 | /* dump flags */ | 45 | /* dump flags */ |
46 | write(1, flags, MAX_NR_KEYMAPS); | 46 | write(STDOUT_FILENO, flags, MAX_NR_KEYMAPS); |
47 | 47 | ||
48 | for (i = 0; i < MAX_NR_KEYMAPS; i++) { | 48 | for (i = 0; i < MAX_NR_KEYMAPS; i++) { |
49 | if (flags[i] == 1) { | 49 | if (flags[i] == 1) { |
@@ -56,11 +56,14 @@ int dumpkmap_main(int argc, char **argv) | |||
56 | (char *)&ke.kb_table, | 56 | (char *)&ke.kb_table, |
57 | &ke.kb_value) | 57 | &ke.kb_value) |
58 | ) { | 58 | ) { |
59 | write(1, (void*)&ke.kb_value, 2); | 59 | write(STDOUT_FILENO, (void*)&ke.kb_value, 2); |
60 | } | 60 | } |
61 | } | 61 | } |
62 | } | 62 | } |
63 | } | 63 | } |
64 | close(fd); | 64 | if (ENABLE_FEATURE_CLEAN_UP) { |
65 | close(fd); | ||
66 | RELEASE_CONFIG_BUFFER(flags); | ||
67 | } | ||
65 | return EXIT_SUCCESS; | 68 | return EXIT_SUCCESS; |
66 | } | 69 | } |
diff --git a/console-tools/kbd_mode.c b/console-tools/kbd_mode.c index 46ec3fd28..161495719 100644 --- a/console-tools/kbd_mode.c +++ b/console-tools/kbd_mode.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* | 2 | /* |
3 | * Mini loadkmap implementation for busybox | 3 | * Mini kbd_mode implementation for busybox |
4 | * | 4 | * |
5 | * Copyright (C) 2007 Lo�c Greni� <loic.grenie@gmail.com> | 5 | * Copyright (C) 2007 Lo�c Greni� <loic.grenie@gmail.com> |
6 | * written using Andries Brouwer <aeb@cwi.nl>'s kbd_mode from | 6 | * written using Andries Brouwer <aeb@cwi.nl>'s kbd_mode from |
@@ -14,54 +14,39 @@ | |||
14 | #include <linux/kd.h> | 14 | #include <linux/kd.h> |
15 | 15 | ||
16 | int kbd_mode_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 16 | int kbd_mode_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
17 | int kbd_mode_main(int argc, char **argv) | 17 | int kbd_mode_main(int ATTRIBUTE_UNUSED argc, char **argv) |
18 | { | 18 | { |
19 | static const char opts[] = "saku"; | ||
20 | |||
21 | const char *opt = argv[1]; | ||
22 | const char *p; | ||
23 | int fd; | 19 | int fd; |
24 | 20 | unsigned opt; | |
21 | enum { | ||
22 | SCANCODE = (1<<0), | ||
23 | ASCII = (1<<1), | ||
24 | MEDIUMRAW= (1<<2), | ||
25 | UNICODE = (1<<3) | ||
26 | }; | ||
27 | static const char KD_xxx[] ALIGN1 = "saku"; | ||
28 | opt = getopt32(argv, KD_xxx); | ||
25 | fd = get_console_fd(); | 29 | fd = get_console_fd(); |
26 | if (fd < 0) /* get_console_fd() already complained */ | 30 | /* if (fd < 0) |
27 | return EXIT_FAILURE; | 31 | return EXIT_FAILURE; |
32 | */ | ||
33 | if (!opt) { /* print current setting */ | ||
34 | const char *mode = "unknown"; | ||
35 | int m; | ||
28 | 36 | ||
29 | if (opt == NULL) { | 37 | ioctl(fd, KDGKBMODE, &m); |
30 | /* No arg */ | 38 | if (m == K_RAW) |
31 | const char *msg = "unknown"; | 39 | mode = "raw (scancode)"; |
32 | int mode; | 40 | else if (m == K_XLATE) |
33 | 41 | mode = "default (ASCII)"; | |
34 | ioctl(fd, KDGKBMODE, &mode); | 42 | else if (m == K_MEDIUMRAW) |
35 | switch(mode) { | 43 | mode = "mediumraw (keycode)"; |
36 | case K_RAW: | 44 | else if (m == K_UNICODE) |
37 | msg = "raw (scancode)"; | 45 | mode = "Unicode (UTF-8)"; |
38 | break; | 46 | printf("The keyboard is in %s mode\n", mode); |
39 | case K_XLATE: | 47 | } else { |
40 | msg = "default (ASCII)"; | 48 | opt = opt & UNICODE ? 3 : opt >> 1; |
41 | break; | 49 | xioctl(fd, KDSKBMODE, &opt); |
42 | case K_MEDIUMRAW: | ||
43 | msg = "mediumraw (keycode)"; | ||
44 | break; | ||
45 | case K_UNICODE: | ||
46 | msg = "Unicode (UTF-8)"; | ||
47 | break; | ||
48 | } | ||
49 | printf("The keyboard is in %s mode\n", msg); | ||
50 | } | ||
51 | else if (argc > 2 /* more than 1 arg */ | ||
52 | || *opt != '-' /* not an option */ | ||
53 | || (p = strchr(opts, opt[1])) == NULL /* not an option we expect */ | ||
54 | || opt[2] != '\0' /* more than one option char */ | ||
55 | ) { | ||
56 | bb_show_usage(); | ||
57 | /* return EXIT_FAILURE; - not reached */ | ||
58 | } | ||
59 | else { | ||
60 | #if K_RAW != 0 || K_XLATE != 1 || K_MEDIUMRAW != 2 || K_UNICODE != 3 | ||
61 | #error kbd_mode must be changed | ||
62 | #endif | ||
63 | /* The options are in the order of the various K_xxx */ | ||
64 | ioctl(fd, KDSKBMODE, p - opts); | ||
65 | } | 50 | } |
66 | 51 | ||
67 | if (ENABLE_FEATURE_CLEAN_UP) | 52 | if (ENABLE_FEATURE_CLEAN_UP) |
diff --git a/console-tools/loadkmap.c b/console-tools/loadkmap.c index bea5a771f..28e53ebca 100644 --- a/console-tools/loadkmap.c +++ b/console-tools/loadkmap.c | |||
@@ -26,28 +26,26 @@ struct kbentry { | |||
26 | #define MAX_NR_KEYMAPS 256 | 26 | #define MAX_NR_KEYMAPS 256 |
27 | 27 | ||
28 | int loadkmap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 28 | int loadkmap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
29 | int loadkmap_main(int argc, char **argv ATTRIBUTE_UNUSED) | 29 | int loadkmap_main(int ATTRIBUTE_UNUSED argc, char **argv ATTRIBUTE_UNUSED) |
30 | { | 30 | { |
31 | struct kbentry ke; | 31 | struct kbentry ke; |
32 | int i, j, fd; | 32 | int i, j, fd; |
33 | uint16_t ibuff[NR_KEYS]; | 33 | uint16_t ibuff[NR_KEYS]; |
34 | char flags[MAX_NR_KEYMAPS]; | 34 | RESERVE_CONFIG_BUFFER(flags,MAX_NR_KEYMAPS); |
35 | char buff[7]; | ||
36 | 35 | ||
37 | if (argc != 1) | 36 | /* bb_warn_ignoring_args(argc>=2);*/ |
38 | bb_show_usage(); | ||
39 | 37 | ||
40 | fd = xopen(CURRENT_VC, O_RDWR); | 38 | fd = xopen(CURRENT_VC, O_RDWR); |
41 | 39 | ||
42 | xread(0, buff, 7); | 40 | xread(STDIN_FILENO, flags, 7); |
43 | if (strncmp(buff, BINARY_KEYMAP_MAGIC, 7)) | 41 | if (strncmp(flags, BINARY_KEYMAP_MAGIC, 7)) |
44 | bb_error_msg_and_die("this is not a valid binary keymap"); | 42 | bb_error_msg_and_die("not a valid binary keymap"); |
45 | 43 | ||
46 | xread(0, flags, MAX_NR_KEYMAPS); | 44 | xread(STDIN_FILENO, flags, MAX_NR_KEYMAPS); |
47 | 45 | ||
48 | for (i = 0; i < MAX_NR_KEYMAPS; i++) { | 46 | for (i = 0; i < MAX_NR_KEYMAPS; i++) { |
49 | if (flags[i] == 1) { | 47 | if (flags[i] == 1) { |
50 | xread(0, ibuff, NR_KEYS * sizeof(uint16_t)); | 48 | xread(STDIN_FILENO, ibuff, NR_KEYS * sizeof(uint16_t)); |
51 | for (j = 0; j < NR_KEYS; j++) { | 49 | for (j = 0; j < NR_KEYS; j++) { |
52 | ke.kb_index = j; | 50 | ke.kb_index = j; |
53 | ke.kb_table = i; | 51 | ke.kb_table = i; |
@@ -57,6 +55,9 @@ int loadkmap_main(int argc, char **argv ATTRIBUTE_UNUSED) | |||
57 | } | 55 | } |
58 | } | 56 | } |
59 | 57 | ||
60 | if (ENABLE_FEATURE_CLEAN_UP) close(fd); | 58 | if (ENABLE_FEATURE_CLEAN_UP) { |
61 | return 0; | 59 | close(fd); |
60 | RELEASE_CONFIG_BUFFER(flags); | ||
61 | } | ||
62 | return EXIT_SUCCESS; | ||
62 | } | 63 | } |
diff --git a/console-tools/openvt.c b/console-tools/openvt.c index c4746dfd3..208522418 100644 --- a/console-tools/openvt.c +++ b/console-tools/openvt.c | |||
@@ -61,7 +61,8 @@ static int get_vt_fd(void) | |||
61 | for (fd = 0; fd < 3; fd++) | 61 | for (fd = 0; fd < 3; fd++) |
62 | if (!not_vt_fd(fd)) | 62 | if (!not_vt_fd(fd)) |
63 | return fd; | 63 | return fd; |
64 | /* _only_ O_NONBLOCK: ask for neither read not write perms */ | 64 | /* _only_ O_NONBLOCK: ask for neither read nor write perms */ |
65 | /*FIXME: use? device_open(DEV_CONSOLE,0); */ | ||
65 | fd = open(DEV_CONSOLE, O_NONBLOCK); | 66 | fd = open(DEV_CONSOLE, O_NONBLOCK); |
66 | if (fd >= 0 && !not_vt_fd(fd)) | 67 | if (fd >= 0 && !not_vt_fd(fd)) |
67 | return fd; | 68 | return fd; |
@@ -93,7 +94,7 @@ static NOINLINE void vfork_child(char **argv) | |||
93 | /* CHILD */ | 94 | /* CHILD */ |
94 | /* Try to make this VT our controlling tty */ | 95 | /* Try to make this VT our controlling tty */ |
95 | setsid(); /* lose old ctty */ | 96 | setsid(); /* lose old ctty */ |
96 | ioctl(0, TIOCSCTTY, 0 /* 0: don't forcibly steal */); | 97 | ioctl(STDIN_FILENO, TIOCSCTTY, 0 /* 0: don't forcibly steal */); |
97 | //bb_error_msg("our sid %d", getsid(0)); | 98 | //bb_error_msg("our sid %d", getsid(0)); |
98 | //bb_error_msg("our pgrp %d", getpgrp()); | 99 | //bb_error_msg("our pgrp %d", getpgrp()); |
99 | //bb_error_msg("VT's sid %d", tcgetsid(0)); | 100 | //bb_error_msg("VT's sid %d", tcgetsid(0)); |
@@ -135,14 +136,13 @@ int openvt_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
135 | sprintf(vtname, VC_FORMAT, vtno); | 136 | sprintf(vtname, VC_FORMAT, vtno); |
136 | /* (Try to) clean up stray open fds above fd 2 */ | 137 | /* (Try to) clean up stray open fds above fd 2 */ |
137 | bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS | DAEMON_ONLY_SANITIZE, NULL); | 138 | bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS | DAEMON_ONLY_SANITIZE, NULL); |
138 | close(0); | 139 | close(STDIN_FILENO); |
139 | /*setsid(); - BAD IDEA: after we exit, child is SIGHUPed... */ | 140 | /*setsid(); - BAD IDEA: after we exit, child is SIGHUPed... */ |
140 | xopen(vtname, O_RDWR); | 141 | xopen(vtname, O_RDWR); |
141 | xioctl(0, VT_GETSTATE, &vtstat); | 142 | xioctl(STDIN_FILENO, VT_GETSTATE, &vtstat); |
142 | 143 | ||
143 | if (flags & OPT_s) { | 144 | if (flags & OPT_s) { |
144 | xioctl(0, VT_ACTIVATE, (void*)(ptrdiff_t)vtno); | 145 | console_make_active(STDIN_FILENO, vtno); |
145 | xioctl(0, VT_WAITACTIVE, (void*)(ptrdiff_t)vtno); | ||
146 | } | 146 | } |
147 | 147 | ||
148 | if (!argv[0]) { | 148 | if (!argv[0]) { |
@@ -153,14 +153,16 @@ int openvt_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
153 | /*argv[1] = NULL; - already is */ | 153 | /*argv[1] = NULL; - already is */ |
154 | } | 154 | } |
155 | 155 | ||
156 | xdup2(0, STDOUT_FILENO); | 156 | xdup2(STDIN_FILENO, STDOUT_FILENO); |
157 | xdup2(0, STDERR_FILENO); | 157 | xdup2(STDIN_FILENO, STDERR_FILENO); |
158 | 158 | ||
159 | #ifdef BLOAT | 159 | #ifdef BLOAT |
160 | { | ||
160 | /* Handle -l (login shell) option */ | 161 | /* Handle -l (login shell) option */ |
161 | const char *prog = argv[0]; | 162 | const char *prog = argv[0]; |
162 | if (flags & OPT_l) | 163 | if (flags & OPT_l) |
163 | argv[0] = xasprintf("-%s", argv[0]); | 164 | argv[0] = xasprintf("-%s", argv[0]); |
165 | } | ||
164 | #endif | 166 | #endif |
165 | 167 | ||
166 | vfork_child(argv); | 168 | vfork_child(argv); |
@@ -168,12 +170,11 @@ int openvt_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
168 | /* We have only one child, wait for it */ | 170 | /* We have only one child, wait for it */ |
169 | safe_waitpid(-1, NULL, 0); /* loops on EINTR */ | 171 | safe_waitpid(-1, NULL, 0); /* loops on EINTR */ |
170 | if (flags & OPT_s) { | 172 | if (flags & OPT_s) { |
171 | xioctl(0, VT_ACTIVATE, (void*)(ptrdiff_t)(vtstat.v_active)); | 173 | console_make_active(STDIN_FILENO, vtstat.v_active); |
172 | xioctl(0, VT_WAITACTIVE, (void*)(ptrdiff_t)(vtstat.v_active)); | ||
173 | // Compat: even with -c N (try to) disallocate: | 174 | // Compat: even with -c N (try to) disallocate: |
174 | // # /usr/app/kbd-1.12/bin/openvt -f -c 9 -ws sleep 5 | 175 | // # /usr/app/kbd-1.12/bin/openvt -f -c 9 -ws sleep 5 |
175 | // openvt: could not deallocate console 9 | 176 | // openvt: could not deallocate console 9 |
176 | xioctl(0, VT_DISALLOCATE, (void*)(ptrdiff_t)vtno); | 177 | xioctl(STDIN_FILENO, VT_DISALLOCATE, (void*)(ptrdiff_t)vtno); |
177 | } | 178 | } |
178 | } | 179 | } |
179 | return EXIT_SUCCESS; | 180 | return EXIT_SUCCESS; |
diff --git a/console-tools/reset.c b/console-tools/reset.c index a2bf44d9f..5d5d4e27b 100644 --- a/console-tools/reset.c +++ b/console-tools/reset.c | |||
@@ -26,7 +26,7 @@ int reset_main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) | |||
26 | 26 | ||
27 | /* no options, no getopt */ | 27 | /* no options, no getopt */ |
28 | 28 | ||
29 | if (isatty(0) && isatty(1)) { | 29 | if (isatty(STDIN_FILENO) && isatty(STDOUT_FILENO)) { |
30 | /* See 'man 4 console_codes' for details: | 30 | /* See 'man 4 console_codes' for details: |
31 | * "ESC c" -- Reset | 31 | * "ESC c" -- Reset |
32 | * "ESC ( K" -- Select user mapping | 32 | * "ESC ( K" -- Select user mapping |
diff --git a/console-tools/setconsole.c b/console-tools/setconsole.c index 8765a7c2e..82fe83f22 100644 --- a/console-tools/setconsole.c +++ b/console-tools/setconsole.c | |||
@@ -3,40 +3,34 @@ | |||
3 | * setconsole.c - redirect system console output | 3 | * setconsole.c - redirect system console output |
4 | * | 4 | * |
5 | * Copyright (C) 2004,2005 Enrik Berkhan <Enrik.Berkhan@inka.de> | 5 | * Copyright (C) 2004,2005 Enrik Berkhan <Enrik.Berkhan@inka.de> |
6 | * Copyright (C) 2008 Bernhard Fischer | ||
6 | * | 7 | * |
7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 8 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
8 | */ | 9 | */ |
9 | 10 | ||
10 | #include "libbb.h" | 11 | #include "libbb.h" |
11 | 12 | ||
12 | #if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS | ||
13 | static const char setconsole_longopts[] ALIGN1 = | ||
14 | "reset\0" No_argument "r" | ||
15 | ; | ||
16 | #endif | ||
17 | |||
18 | #define OPT_SETCONS_RESET 1 | ||
19 | |||
20 | int setconsole_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 13 | int setconsole_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
21 | int setconsole_main(int argc, char **argv) | 14 | int setconsole_main(int ATTRIBUTE_UNUSED argc, char **argv) |
22 | { | 15 | { |
23 | unsigned long flags; | ||
24 | const char *device = CURRENT_TTY; | 16 | const char *device = CURRENT_TTY; |
17 | bool reset; | ||
25 | 18 | ||
26 | #if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS | 19 | #if ENABLE_FEATURE_SETCONSOLE_LONG_OPTIONS |
20 | static const char setconsole_longopts[] ALIGN1 = | ||
21 | "reset\0" No_argument "r" | ||
22 | ; | ||
27 | applet_long_options = setconsole_longopts; | 23 | applet_long_options = setconsole_longopts; |
28 | #endif | 24 | #endif |
29 | flags = getopt32(argv, "r"); | 25 | /* at most one non-option argument */ |
30 | 26 | opt_complementary = "?1"; | |
31 | if (argc - optind > 1) | 27 | reset = getopt32(argv, "r"); |
32 | bb_show_usage(); | ||
33 | 28 | ||
34 | if (argc - optind == 1) { | 29 | argv += 1 + reset; |
35 | if (flags & OPT_SETCONS_RESET) | 30 | if (*argv) { |
36 | bb_show_usage(); | 31 | device = *argv; |
37 | device = argv[optind]; | ||
38 | } else { | 32 | } else { |
39 | if (flags & OPT_SETCONS_RESET) | 33 | if (reset) |
40 | device = DEV_CONSOLE; | 34 | device = DEV_CONSOLE; |
41 | } | 35 | } |
42 | 36 | ||
diff --git a/console-tools/setlogcons.c b/console-tools/setlogcons.c index b312fa76e..aa8e0806f 100644 --- a/console-tools/setlogcons.c +++ b/console-tools/setlogcons.c | |||
@@ -17,15 +17,14 @@ int setlogcons_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
17 | struct { | 17 | struct { |
18 | char fn; | 18 | char fn; |
19 | char subarg; | 19 | char subarg; |
20 | } arg; | 20 | } arg = { 11, /* redirect kernel messages */ |
21 | 21 | 0 /* to specified console (current as default) */ | |
22 | arg.fn = 11; /* redirect kernel messages */ | 22 | }; |
23 | arg.subarg = 0; /* to specified console (current as default) */ | ||
24 | 23 | ||
25 | if (argv[1]) | 24 | if (argv[1]) |
26 | arg.subarg = xatou_range(argv[1], 0, 63); | 25 | arg.subarg = xatou_range(argv[1], 0, 63); |
27 | 26 | ||
28 | xioctl(xopen(VC_1, O_RDONLY), TIOCLINUX, &arg); | 27 | xioctl(xopen(VC_1, O_RDONLY), TIOCLINUX, &arg); |
29 | 28 | ||
30 | return 0; | 29 | return EXIT_SUCCESS; |
31 | } | 30 | } |