*: use get_console_fd() as appropriate, and make it fail on open error -
authorDenis Vlasenko <vda.linux@googlemail.com>
Tue, 5 Aug 2008 23:32:27 +0000 (23:32 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Tue, 5 Aug 2008 23:32:27 +0000 (23:32 -0000)
 get_console_fd_or_die().

function                                             old     new   delta
get_console_fd_or_die                                  -     163    +163
loadkmap_main                                        211     201     -10
loadfont_main                                        440     430     -10
dumpkmap_main                                        218     208     -10
kbd_mode_main                                        158     146     -12
setkeycodes_main                                     156     143     -13
get_console_fd                                       163       -    -163
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 0/5 up/down: 163/-218)          Total: -55 bytes

console-tools/chvt.c
console-tools/deallocvt.c
console-tools/dumpkmap.c
console-tools/kbd_mode.c
console-tools/loadfont.c
console-tools/loadkmap.c
console-tools/setkeycodes.c
include/libbb.h
libbb/get_console.c

index ea3e7c04857259b06aea2714cb697b6a06c32d4b..302ffb4f914fa300f8f1f2d0ec9c2bcee9e9219c 100644 (file)
@@ -19,7 +19,6 @@ int chvt_main(int argc, char **argv)
        }
 
        num = xatou_range(argv[1], 1, 63);
-       /* double cast suppresses "cast to ptr from int of different size" */
-       console_make_active(get_console_fd(), num);
+       console_make_active(get_console_fd_or_die(), num);
        return EXIT_SUCCESS;
 }
index e9a3989c7680fe371164f63a8877dc701d6d47db..09748834feabfcfa12953b1cc3dfeb1b6ec440bf 100644 (file)
@@ -28,6 +28,6 @@ int deallocvt_main(int argc UNUSED_PARAM, char **argv)
        }
 
        /* double cast suppresses "cast to ptr from int of different size" */
-       xioctl(get_console_fd(), VT_DISALLOCATE, (void *)(ptrdiff_t)num);
+       xioctl(get_console_fd_or_die(), VT_DISALLOCATE, (void *)(ptrdiff_t)num);
        return EXIT_SUCCESS;
 }
index 1d6bbdc63064c1561102bb520bcf4abe84a73616..c382b5af995bb69772b7e3de917efd7817a47e24 100644 (file)
@@ -32,7 +32,7 @@ int dumpkmap_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
 
 /*     bb_warn_ignoring_args(argc>=2);*/
 
-       fd = xopen(CURRENT_VC, O_RDWR);
+       fd = get_console_fd_or_die();
 
        write(STDOUT_FILENO, "bkeymap", 7);
 
index 2162fd4fc4574df00623003a78cc8ba14a1f6e08..cb97947ce60c51c905686bfc2bc4d162b566b6cd 100644 (file)
@@ -19,17 +19,15 @@ int kbd_mode_main(int argc UNUSED_PARAM, char **argv)
        int fd;
        unsigned opt;
        enum {
-               SCANCODE = (1<<0),
-               ASCII    = (1<<1),
-               MEDIUMRAW= (1<<2),
-               UNICODE  = (1<<3)
+               SCANCODE  = (1 << 0),
+               ASCII     = (1 << 1),
+               MEDIUMRAW = (1 << 2),
+               UNICODE   = (1 << 3)
        };
        static const char KD_xxx[] ALIGN1 = "saku";
        opt = getopt32(argv, KD_xxx);
-       fd = get_console_fd();
-/*     if (fd < 0)
-               return EXIT_FAILURE;
-*/
+       fd = get_console_fd_or_die();
+
        if (!opt) { /* print current setting */
                const char *mode = "unknown";
                int m;
@@ -46,7 +44,8 @@ int kbd_mode_main(int argc UNUSED_PARAM, char **argv)
                printf("The keyboard is in %s mode\n", mode);
        } else {
                opt = opt & UNICODE ? 3 : opt >> 1;
-               xioctl(fd, KDSKBMODE, opt);
+               /* double cast prevents warnings about widening conversion */
+               xioctl(fd, KDSKBMODE, (void*)(ptrdiff_t)opt);
        }
 
        if (ENABLE_FEATURE_CLEAN_UP)
index 48b298002d5bdf44483f526615737c783cbb2283..567aa38aeb94453009d90d4596eae5ee6852f060 100644 (file)
@@ -174,7 +174,7 @@ int loadfont_main(int argc, char **argv UNUSED_PARAM)
        if (argc != 1)
                bb_show_usage();
 
-       fd = xopen(CURRENT_VC, O_RDWR);
+       fd = get_console_fd_or_die();
        loadnewfont(fd);
 
        return EXIT_SUCCESS;
index b891c9b0e47e324856e3a7726fc80861648536e3..56948e0d054a8dd16c92b68fb337990a926f8218 100644 (file)
@@ -35,7 +35,7 @@ int loadkmap_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
 
 /*  bb_warn_ignoring_args(argc>=2);*/
 
-       fd = xopen(CURRENT_VC, O_RDWR);
+       fd = get_console_fd_or_die();
 
        xread(STDIN_FILENO, flags, 7);
        if (strncmp(flags, BINARY_KEYMAP_MAGIC, 7))
index e9a050862b9187c72f74cafc35d54185b4429f37..597272a2feaed1817e942fda727499d48ced32fd 100644 (file)
@@ -26,11 +26,11 @@ int setkeycodes_main(int argc, char **argv)
        int fd, sc;
        struct kbkeycode a;
 
-       if (argc % 2 != 1 || argc < 2) {
+       if (!(argc & 1) /* if even */ || argc < 2) {
                bb_show_usage();
        }
 
-       fd = get_console_fd();
+       fd = get_console_fd_or_die();
 
        while (argc > 2) {
                a.keycode = xatou_range(argv[2], 0, 127);
@@ -40,7 +40,7 @@ int setkeycodes_main(int argc, char **argv)
                        a.scancode += 128;
                }
                ioctl_or_perror_and_die(fd, KDSETKEYCODE, &a,
-                       "failed to set SCANCODE %x to KEYCODE %d",
+                       "can't set SCANCODE %x to KEYCODE %d",
                        sc, a.keycode);
                argc -= 2;
                argv += 2;
index 3996846b5517ec2c18abd14eb27db3421f854981..075fa055d9f4981e742dbc87e3e00c36ad7b8d0e 100644 (file)
@@ -287,7 +287,7 @@ extern int recursive_action(const char *fileName, unsigned flags,
 extern int device_open(const char *device, int mode) FAST_FUNC;
 enum { GETPTY_BUFSIZE = 16 }; /* more than enough for "/dev/ttyXXX" */
 extern int xgetpty(char *line) FAST_FUNC;
-extern int get_console_fd(void) FAST_FUNC;
+extern int get_console_fd_or_die(void) FAST_FUNC;
 extern void console_make_active(int fd, const int vt_num) FAST_FUNC;
 extern char *find_block_device(const char *path) FAST_FUNC;
 /* bb_copyfd_XX print read/write errors and return -1 if they occur */
index d042afa2b52f3ba15c1102567553e07a028f3dbf..ad56e740f7ee68ba5584c4e09096e6dcc3c509a5 100644 (file)
@@ -38,7 +38,7 @@ static int open_a_console(const char *fnam)
  * if someone else used X (which does a chown on /dev/console).
  */
 
-int FAST_FUNC get_console_fd(void)
+int FAST_FUNC get_console_fd_or_die(void)
 {
        static const char *const console_names[] = {
                DEV_CONSOLE, CURRENT_VC, CURRENT_TTY
@@ -65,8 +65,8 @@ int FAST_FUNC get_console_fd(void)
                }
        }
 
-       bb_error_msg("can't open console");
-       return fd;                      /* total failure */
+       bb_error_msg_and_die("can't open console");
+       /*return fd; - total failure */
 }
 
 /* From <linux/vt.h> */