extern int setkeycodes_main(int argc, char** argv) { char *ep; int fd, sc; struct kbkeycode a; if (argc % 2 != 1 || argc < 2) { bb_show_usage(); } fd = get_console_fd(); while (argc > 2) { a.keycode = atoi(argv[2]); a.scancode = sc = strtol(argv[1], &ep, 16); if (*ep) { bb_error_msg_and_die("error reading SCANCODE: '%s'", argv[1]); } if (a.scancode > 127) { a.scancode -= 0xe000; a.scancode += 128; } if (a.scancode > 255 || a.keycode > 127) { bb_error_msg_and_die("SCANCODE or KEYCODE outside bounds"); } if (ioctl(fd,KDSETKEYCODE,&a)) { perror("KDSETKEYCODE"); bb_error_msg_and_die("failed to set SCANCODE %x to KEYCODE %d", sc, a.keycode); } argc -= 2; argv += 2; } return EXIT_SUCCESS; }
/** * Get a file descriptor for a console to write to */ static int get_console_fd(const char *console_path) { int i, fd; char type = NULL; // Use one of the default console paths if ( ! console_path) { for (i = 0; console_paths[i]; ++i) { if ((fd = get_console_fd(console_paths[i])) > 0) return fd; } return -1; } // Attempt to open the FD, and make sure it's a tty if ((fd = open(console_path, O_RDWR | O_NOCTTY)) < 0) return -1; // Make sure the tty is a linux VT101 terminal if ( ! isatty(fd) || ioctl(fd, KDGKBTYPE, &type) < 0 || type != KB_101) return -1; return fd; }
int chvt_main(int argc, char **argv) { int fd, num; if (argc != 2) { bb_show_usage(); } fd = get_console_fd(); num = xatou_range(argv[1], 1, 63); /* double cast suppresses "cast to ptr from int of different size */ xioctl(fd, VT_ACTIVATE, (void *)(ptrdiff_t)num); xioctl(fd, VT_WAITACTIVE, (void *)(ptrdiff_t)num); return EXIT_SUCCESS; }
int chvt_main(int argc, char **argv) { int fd, num; if (argc != 2) { bb_show_usage(); } fd = get_console_fd(); num = bb_xgetlarg(argv[1], 10, 0, INT_MAX); if ((-1 == ioctl(fd, VT_ACTIVATE, num)) || (-1 == ioctl(fd, VT_WAITACTIVE, num))) { bb_perror_msg_and_die("ioctl"); } return EXIT_SUCCESS; }
int deallocvt_main(int argc, char *argv[]) { /* num = 0 deallocate all unused consoles */ int num = 0; switch(argc) { case 2: if((num = bb_xgetlarg(argv[1], 10, 0, INT_MAX)) == 0) bb_error_msg_and_die("0: illegal VT number"); /* Fallthrough */ case 1: break; default: bb_show_usage(); } if (-1 == ioctl( get_console_fd(), VT_DISALLOCATE, num )) { bb_perror_msg_and_die("VT_DISALLOCATE"); } return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { // Default the color set to the default colors if none specified char color_set[PALETTE_SIZE][7]; memcpy(color_set, default_color_set, PALETTE_SIZE * 7); // By default let the console path be detected char *console_path = NULL; struct option options[] = { {"console", required_argument, 0, 'c'}, {"help", no_argument, 0, 'h'}, {0, 0, 0, 0} }; char c; while((c = getopt_long(argc, argv, "-c:h", options, NULL)) != -1) { switch(c) { case 'c': console_path = optarg; break; case 'h': printf("%s\n", HELP); return 0; case '\1': if (get_color_set_from_file(optarg, color_set) < 0) { perror("Unable to load color set from file"); exit(1); } break; default: exit(1); } } struct palette new_palette = get_palette_from_color_set((const char (*)[]) color_set); int fd; if ((fd = get_console_fd(console_path)) < 0) { perror("Unable to open console"); exit(1); } if (ioctl(fd, PIO_CMAP, &new_palette) < 0) { perror("Failed to set new color map on console"); exit(1); } // Clear console to fix color artifacts write(fd, "\033[2J\033[1;1H", 10); close(fd); return 0; }