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 | |
| 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
| -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 | ||||
| -rw-r--r-- | include/libbb.h | 4 | ||||
| -rw-r--r-- | include/usage.h | 2 | ||||
| -rw-r--r-- | libbb/Kbuild | 1 | ||||
| -rw-r--r-- | libbb/get_console.c | 14 | ||||
| -rw-r--r-- | libbb/getpty.c | 8 | ||||
| -rw-r--r-- | libbb/write.c | 20 | ||||
| -rw-r--r-- | networking/telnetd.c | 6 | ||||
| -rw-r--r-- | scripts/defconfig | 8 | ||||
| -rw-r--r-- | util-linux/rtcwake.c | 15 | ||||
| -rw-r--r-- | util-linux/script.c | 5 |
18 files changed, 136 insertions, 142 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 | } |
diff --git a/include/libbb.h b/include/libbb.h index 4067063e6..f50ae3604 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
| @@ -281,8 +281,9 @@ extern int recursive_action(const char *fileName, unsigned flags, | |||
| 281 | void* userData, unsigned depth); | 281 | void* userData, unsigned depth); |
| 282 | extern int device_open(const char *device, int mode); | 282 | extern int device_open(const char *device, int mode); |
| 283 | enum { GETPTY_BUFSIZE = 16 }; /* more than enough for "/dev/ttyXXX" */ | 283 | enum { GETPTY_BUFSIZE = 16 }; /* more than enough for "/dev/ttyXXX" */ |
| 284 | extern int getpty(char *line); | 284 | extern int xgetpty(char *line); |
| 285 | extern int get_console_fd(void); | 285 | extern int get_console_fd(void); |
| 286 | extern void console_make_active(int fd, const int vt_num); | ||
| 286 | extern char *find_block_device(const char *path); | 287 | extern char *find_block_device(const char *path); |
| 287 | /* bb_copyfd_XX print read/write errors and return -1 if they occur */ | 288 | /* bb_copyfd_XX print read/write errors and return -1 if they occur */ |
| 288 | extern off_t bb_copyfd_eof(int fd1, int fd2); | 289 | extern off_t bb_copyfd_eof(int fd1, int fd2); |
| @@ -590,6 +591,7 @@ extern ssize_t safe_write(int fd, const void *buf, size_t count); | |||
| 590 | // if some data was written before error occurred | 591 | // if some data was written before error occurred |
| 591 | extern ssize_t full_write(int fd, const void *buf, size_t count); | 592 | extern ssize_t full_write(int fd, const void *buf, size_t count); |
| 592 | extern void xwrite(int fd, const void *buf, size_t count); | 593 | extern void xwrite(int fd, const void *buf, size_t count); |
| 594 | extern void xopen_xwrite_close(const char* file, const char *str); | ||
| 593 | 595 | ||
| 594 | /* Reads and prints to stdout till eof, then closes FILE. Exits on error: */ | 596 | /* Reads and prints to stdout till eof, then closes FILE. Exits on error: */ |
| 595 | extern void xprint_and_close_file(FILE *file); | 597 | extern void xprint_and_close_file(FILE *file); |
diff --git a/include/usage.h b/include/usage.h index d5c53a255..cffe78220 100644 --- a/include/usage.h +++ b/include/usage.h | |||
| @@ -875,7 +875,7 @@ | |||
| 875 | #define dumpkmap_trivial_usage \ | 875 | #define dumpkmap_trivial_usage \ |
| 876 | "> keymap" | 876 | "> keymap" |
| 877 | #define dumpkmap_full_usage "\n\n" \ | 877 | #define dumpkmap_full_usage "\n\n" \ |
| 878 | "Print out a binary keyboard translation table to standard output" | 878 | "Print a binary keyboard translation table to standard output" |
| 879 | #define dumpkmap_example_usage \ | 879 | #define dumpkmap_example_usage \ |
| 880 | "$ dumpkmap > keymap\n" | 880 | "$ dumpkmap > keymap\n" |
| 881 | 881 | ||
diff --git a/libbb/Kbuild b/libbb/Kbuild index d943628aa..0c7e25497 100644 --- a/libbb/Kbuild +++ b/libbb/Kbuild | |||
| @@ -98,6 +98,7 @@ lib-y += vfork_daemon_rexec.o | |||
| 98 | lib-y += warn_ignoring_args.o | 98 | lib-y += warn_ignoring_args.o |
| 99 | lib-y += wfopen.o | 99 | lib-y += wfopen.o |
| 100 | lib-y += wfopen_input.o | 100 | lib-y += wfopen_input.o |
| 101 | lib-y += write.o | ||
| 101 | lib-y += xatonum.o | 102 | lib-y += xatonum.o |
| 102 | lib-y += xconnect.o | 103 | lib-y += xconnect.o |
| 103 | lib-y += xfuncs.o | 104 | lib-y += xfuncs.o |
diff --git a/libbb/get_console.c b/libbb/get_console.c index 0da27b1e2..36fe20426 100644 --- a/libbb/get_console.c +++ b/libbb/get_console.c | |||
| @@ -8,10 +8,8 @@ | |||
| 8 | * 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. |
| 9 | */ | 9 | */ |
| 10 | 10 | ||
| 11 | //#include <sys/ioctl.h> | ||
| 12 | #include "libbb.h" | 11 | #include "libbb.h" |
| 13 | 12 | ||
| 14 | |||
| 15 | /* From <linux/kd.h> */ | 13 | /* From <linux/kd.h> */ |
| 16 | enum { KDGKBTYPE = 0x4B33 }; /* get keyboard type */ | 14 | enum { KDGKBTYPE = 0x4B33 }; /* get keyboard type */ |
| 17 | 15 | ||
| @@ -70,3 +68,15 @@ int get_console_fd(void) | |||
| 70 | bb_error_msg("can't open console"); | 68 | bb_error_msg("can't open console"); |
| 71 | return fd; /* total failure */ | 69 | return fd; /* total failure */ |
| 72 | } | 70 | } |
| 71 | |||
| 72 | /* From <linux/vt.h> */ | ||
| 73 | enum { | ||
| 74 | VT_ACTIVATE = 0x5606, /* make vt active */ | ||
| 75 | VT_WAITACTIVE = 0x5607 /* wait for vt active */ | ||
| 76 | }; | ||
| 77 | |||
| 78 | void console_make_active(int fd, const int vt_num) | ||
| 79 | { | ||
| 80 | xioctl(fd, VT_ACTIVATE, (void *)(ptrdiff_t)vt_num); | ||
| 81 | xioctl(fd, VT_WAITACTIVE, (void *)(ptrdiff_t)vt_num); | ||
| 82 | } | ||
diff --git a/libbb/getpty.c b/libbb/getpty.c index 5ac9582d3..d43fb825f 100644 --- a/libbb/getpty.c +++ b/libbb/getpty.c | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | 10 | ||
| 11 | #define DEBUG 0 | 11 | #define DEBUG 0 |
| 12 | 12 | ||
| 13 | int getpty(char *line) | 13 | int xgetpty(char *line) |
| 14 | { | 14 | { |
| 15 | int p; | 15 | int p; |
| 16 | #if ENABLE_FEATURE_DEVPTS | 16 | #if ENABLE_FEATURE_DEVPTS |
| @@ -22,7 +22,7 @@ int getpty(char *line) | |||
| 22 | name = ptsname(p); | 22 | name = ptsname(p); |
| 23 | if (!name) { | 23 | if (!name) { |
| 24 | bb_perror_msg("ptsname error (is /dev/pts mounted?)"); | 24 | bb_perror_msg("ptsname error (is /dev/pts mounted?)"); |
| 25 | return -1; | 25 | goto fail; |
| 26 | } | 26 | } |
| 27 | safe_strncpy(line, name, GETPTY_BUFSIZE); | 27 | safe_strncpy(line, name, GETPTY_BUFSIZE); |
| 28 | return p; | 28 | return p; |
| @@ -52,7 +52,9 @@ int getpty(char *line) | |||
| 52 | } | 52 | } |
| 53 | } | 53 | } |
| 54 | #endif /* FEATURE_DEVPTS */ | 54 | #endif /* FEATURE_DEVPTS */ |
| 55 | return -1; | 55 | USE_FEATURE_DEVPTS( fail:) |
| 56 | bb_error_msg_and_die("open pty"); | ||
| 57 | return -1; /* never get here */ | ||
| 56 | } | 58 | } |
| 57 | 59 | ||
| 58 | 60 | ||
diff --git a/libbb/write.c b/libbb/write.c new file mode 100644 index 000000000..b628b49bb --- /dev/null +++ b/libbb/write.c | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | ||
| 2 | /* | ||
| 3 | * Utility routines. | ||
| 4 | * | ||
| 5 | * Copyright (C) 2008 Bernhard Fischer | ||
| 6 | * | ||
| 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | ||
| 8 | */ | ||
| 9 | |||
| 10 | #include "libbb.h" | ||
| 11 | |||
| 12 | /* Open file and write string str to it, close file. | ||
| 13 | * Die on any open or write-error. */ | ||
| 14 | void xopen_xwrite_close(const char* file, const char* str) | ||
| 15 | { | ||
| 16 | int fd = xopen(file, O_WRONLY); | ||
| 17 | |||
| 18 | xwrite(fd, str, strlen(str)); | ||
| 19 | close(fd); | ||
| 20 | } | ||
diff --git a/networking/telnetd.c b/networking/telnetd.c index 5188edbab..e312c0b41 100644 --- a/networking/telnetd.c +++ b/networking/telnetd.c | |||
| @@ -164,11 +164,7 @@ make_new_session( | |||
| 164 | /*ts->buf2 = ts->buf1 + BUFSIZE;*/ | 164 | /*ts->buf2 = ts->buf1 + BUFSIZE;*/ |
| 165 | 165 | ||
| 166 | /* Got a new connection, set up a tty. */ | 166 | /* Got a new connection, set up a tty. */ |
| 167 | fd = getpty(tty_name); | 167 | fd = xgetpty(tty_name); |
| 168 | if (fd < 0) { | ||
| 169 | bb_error_msg("can't create pty"); | ||
| 170 | return NULL; | ||
| 171 | } | ||
| 172 | if (fd > maxfd) | 168 | if (fd > maxfd) |
| 173 | maxfd = fd; | 169 | maxfd = fd; |
| 174 | ts->ptyfd = fd; | 170 | ts->ptyfd = fd; |
diff --git a/scripts/defconfig b/scripts/defconfig index 93b71667a..a71fadd41 100644 --- a/scripts/defconfig +++ b/scripts/defconfig | |||
| @@ -516,7 +516,7 @@ CONFIG_FEATURE_MOUNT_FSTAB=y | |||
| 516 | CONFIG_PIVOT_ROOT=y | 516 | CONFIG_PIVOT_ROOT=y |
| 517 | CONFIG_RDATE=y | 517 | CONFIG_RDATE=y |
| 518 | CONFIG_READPROFILE=y | 518 | CONFIG_READPROFILE=y |
| 519 | # CONFIG_RTCWAKE is not set | 519 | CONFIG_RTCWAKE=y |
| 520 | CONFIG_SETARCH=y | 520 | CONFIG_SETARCH=y |
| 521 | CONFIG_SWAPONOFF=y | 521 | CONFIG_SWAPONOFF=y |
| 522 | CONFIG_SWITCH_ROOT=y | 522 | CONFIG_SWITCH_ROOT=y |
| @@ -534,10 +534,10 @@ CONFIG_FEATURE_MOUNT_LOOP=y | |||
| 534 | # | 534 | # |
| 535 | CONFIG_ADJTIMEX=y | 535 | CONFIG_ADJTIMEX=y |
| 536 | # CONFIG_BBCONFIG is not set | 536 | # CONFIG_BBCONFIG is not set |
| 537 | # CONFIG_CHAT is not set | 537 | CONFIG_CHAT=y |
| 538 | # CONFIG_FEATURE_CHAT_NOFAIL is not set | 538 | CONFIG_FEATURE_CHAT_NOFAIL=y |
| 539 | # CONFIG_FEATURE_CHAT_TTY_HIFI is not set | 539 | # CONFIG_FEATURE_CHAT_TTY_HIFI is not set |
| 540 | # CONFIG_FEATURE_CHAT_IMPLICIT_CR is not set | 540 | CONFIG_FEATURE_CHAT_IMPLICIT_CR=y |
| 541 | # CONFIG_FEATURE_CHAT_SWALLOW_OPTS is not set | 541 | # CONFIG_FEATURE_CHAT_SWALLOW_OPTS is not set |
| 542 | # CONFIG_FEATURE_CHAT_SEND_ESCAPES is not set | 542 | # CONFIG_FEATURE_CHAT_SEND_ESCAPES is not set |
| 543 | # CONFIG_FEATURE_CHAT_VAR_ABORT_LEN is not set | 543 | # CONFIG_FEATURE_CHAT_VAR_ABORT_LEN is not set |
diff --git a/util-linux/rtcwake.c b/util-linux/rtcwake.c index 6df7334fe..515f812b3 100644 --- a/util-linux/rtcwake.c +++ b/util-linux/rtcwake.c | |||
| @@ -30,7 +30,7 @@ | |||
| 30 | 30 | ||
| 31 | static time_t rtc_time; | 31 | static time_t rtc_time; |
| 32 | 32 | ||
| 33 | static int may_wakeup(const char *rtcname) | 33 | static bool may_wakeup(const char *rtcname) |
| 34 | { | 34 | { |
| 35 | ssize_t ret; | 35 | ssize_t ret; |
| 36 | char buf[128]; | 36 | char buf[128]; |
| @@ -42,7 +42,7 @@ static int may_wakeup(const char *rtcname) | |||
| 42 | snprintf(buf, sizeof(buf), SYS_RTC_PATH, rtcname); | 42 | snprintf(buf, sizeof(buf), SYS_RTC_PATH, rtcname); |
| 43 | ret = open_read_close(buf, buf, sizeof(buf)); | 43 | ret = open_read_close(buf, buf, sizeof(buf)); |
| 44 | if (ret < 0) | 44 | if (ret < 0) |
| 45 | return 0; | 45 | return false; |
| 46 | 46 | ||
| 47 | /* wakeup events could be disabled or not supported */ | 47 | /* wakeup events could be disabled or not supported */ |
| 48 | return strncmp(buf, "enabled\n", 8) == 0; | 48 | return strncmp(buf, "enabled\n", 8) == 0; |
| @@ -89,15 +89,6 @@ static void setup_alarm(int fd, time_t *wakeup) | |||
| 89 | } | 89 | } |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | static void suspend_system(const char *suspend) | ||
| 93 | { | ||
| 94 | FILE *f = xfopen(SYS_POWER_PATH, "w"); | ||
| 95 | fprintf(f, "%s\n", suspend); | ||
| 96 | fflush(f); | ||
| 97 | /* this executes after wake from suspend */ | ||
| 98 | fclose(f); | ||
| 99 | } | ||
| 100 | |||
| 101 | #define RTCWAKE_OPT_AUTO 0x01 | 92 | #define RTCWAKE_OPT_AUTO 0x01 |
| 102 | #define RTCWAKE_OPT_LOCAL 0x02 | 93 | #define RTCWAKE_OPT_LOCAL 0x02 |
| 103 | #define RTCWAKE_OPT_UTC 0x04 | 94 | #define RTCWAKE_OPT_UTC 0x04 |
| @@ -185,7 +176,7 @@ int rtcwake_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
| 185 | usleep(10 * 1000); | 176 | usleep(10 * 1000); |
| 186 | 177 | ||
| 187 | if (strcmp(suspend, "on")) | 178 | if (strcmp(suspend, "on")) |
| 188 | suspend_system(suspend); | 179 | xopen_xwrite_close(SYS_POWER_PATH, suspend); |
| 189 | else { | 180 | else { |
| 190 | /* "fake" suspend ... we'll do the delay ourselves */ | 181 | /* "fake" suspend ... we'll do the delay ourselves */ |
| 191 | unsigned long data; | 182 | unsigned long data; |
diff --git a/util-linux/script.c b/util-linux/script.c index 63d3039d3..c1883328f 100644 --- a/util-linux/script.c +++ b/util-linux/script.c | |||
| @@ -69,10 +69,7 @@ int script_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
| 69 | shell = DEFAULT_SHELL; | 69 | shell = DEFAULT_SHELL; |
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | pty = getpty(pty_line); | 72 | pty = xgetpty(pty_line); |
| 73 | if (pty < 0) { | ||
| 74 | bb_perror_msg_and_die("can't get pty"); | ||
| 75 | } | ||
| 76 | 73 | ||
| 77 | /* get current stdin's tty params */ | 74 | /* get current stdin's tty params */ |
| 78 | attr_ok = tcgetattr(0, &tt); | 75 | attr_ok = tcgetattr(0, &tt); |
