int main(int argc, char **argv) { int fd, cons; struct { char fn, subarg; } arg; set_progname(argv[0]); setlocale(LC_ALL, ""); bindtextdomain(PACKAGE_NAME, LOCALEDIR); textdomain(PACKAGE_NAME); if (argc == 2) cons = atoi(argv[1]); else cons = 0; /* current console */ if ((fd = getfd(NULL)) < 0) kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console")); arg.fn = 11; /* redirect kernel messages */ arg.subarg = cons; /* to specified console */ if (ioctl(fd, TIOCLINUX, &arg)) { kbd_error(EXIT_FAILURE, errno, "TIOCLINUX"); } return EXIT_SUCCESS; }
/* * Try to find out proper login name. */ const char * get_username (void) { const char *name; struct passwd *pw = 0; uid_t uid = getuid (); char *logname = getenv ("LOGNAME"); if (logname) { pw = getpwnam (logname); /* Ensure uid is same as current. */ if (pw && pw->pw_uid != uid) pw = 0; } if (!pw) pw = getpwuid (uid); if (!pw) kbd_error (EXIT_FAILURE, 0, _("unrecognized user")); name = strdup (pw->pw_name); if (!name) kbd_error (EXIT_FAILURE, errno, "strdup"); endpwent (); return name; }
int main(int argc, char **argv) { char *ep; int fd; struct kbkeycode a; set_progname(argv[0]); setlocale(LC_ALL, ""); bindtextdomain(PACKAGE_NAME, LOCALEDIR); textdomain(PACKAGE_NAME); if (argc == 2 && !strcmp(argv[1], "-V")) print_version_and_exit(); if (argc % 2 != 1) usage(_("even number of arguments expected")); if ((fd = getfd(NULL)) < 0) kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console")); while (argc > 2) { a.keycode = atoi(argv[2]); a.scancode = strtol(argv[1], &ep, 16); if (*ep) usage(_("error reading scancode")); if (a.scancode >= 0xe000) { a.scancode -= 0xe000; a.scancode += 128; /* some kernels needed +256 */ } #if 0 /* Test is OK up to 2.5.31--later kernels have more keycodes */ if (a.scancode > 255 || a.keycode > 127) usage(_("code outside bounds")); /* Both fields are unsigned int, so can be large; for current kernels the correct test might be (a.scancode > 255 || a.keycode > 239) but we can leave testing to the kernel. */ #endif if (ioctl(fd, KDSETKEYCODE, &a)) { kbd_error(EXIT_FAILURE, errno, _("failed to set scancode %x to keycode %d: ioctl KDSETKEYCODE"), a.scancode, a.keycode); } argc -= 2; argv += 2; } return EXIT_SUCCESS; }
static void sighup(int n __attribute__ ((unused))) { if (system("openvt -s -l -- login -h spawn") == -1) { kbd_error(EXIT_FAILURE, errno, "system"); } signal(SIGHUP, sighup); }
int main(int argc, char **argv) { unsigned int ometa, nmeta; struct meta *mp; set_progname(argv[0]); setlocale(LC_ALL, ""); bindtextdomain(PACKAGE_NAME, LOCALEDIR); textdomain(PACKAGE_NAME); if (argc == 2 && !strcmp(argv[1], "-V")) print_version_and_exit(); if (ioctl(0, KDGKBMETA, &ometa)) { kbd_error(EXIT_FAILURE, errno, _("Error reading current setting. Maybe stdin is not a VT?: " "ioctl KDGKBMETA")); } if (argc <= 1) { report(ometa); exit(EXIT_SUCCESS); } nmeta = 0; /* make gcc happy */ for (mp = metas; (unsigned)(mp - metas) < SIZE(metas); mp++) { if (!strcmp(argv[1], mp->name)) { nmeta = mp->val; goto fnd; } } fprintf(stderr, _("unrecognized argument: _%s_\n\n"), argv[1]); usage(); fnd: printf(_("old state: ")); report(ometa); if (ioctl(0, KDSKBMETA, nmeta)) { kbd_error(EXIT_FAILURE, errno, "ioctl KDSKBMETA"); } printf(_("new state: ")); report(nmeta); return EXIT_SUCCESS; }
static void settrivialscreenmap(void) { unsigned short i; if (getuniscrnmap(fd, obuf)) exit(1); have_obuf = 1; for (i = 0; i < E_TABSZ; i++) nbuf[i] = i; if (loaduniscrnmap(fd, nbuf)) { kbd_error(EXIT_FAILURE, 0, _("cannot change translation table\n")); } }
int main(int argc __attribute__ ((unused)), char *argv[]) { int fd; set_progname(argv[0]); fd = open("/dev/tty0", 0); if (fd < 0 && errno == ENOENT) fd = open("/dev/vc/0", 0); if (fd < 0) fd = 0; signal(SIGHUP, sighup); if (ioctl(fd, KDSIGACCEPT, (long) SIGHUP)) kbd_error(EXIT_FAILURE, errno, "ioctl KDSIGACCEPT"); while(1) sleep(3600); return EXIT_SUCCESS; }
int main(int argc, char **argv) { int c, n, cols, rows, nr, i, j, k; int mode; const char *space, *sep; char *console = NULL; int list[64], lth, info = 0, verbose = 0; set_progname(argv[0]); setlocale(LC_ALL, ""); bindtextdomain(PACKAGE_NAME, LOCALEDIR); textdomain(PACKAGE_NAME); if (argc == 2 && (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version"))) print_version_and_exit(); while ((c = getopt(argc, argv, "ivC:")) != EOF) { switch (c) { case 'i': info = 1; break; case 'v': verbose = 1; break; case 'C': console = optarg; break; default: usage(); } } if (optind != argc) usage(); if ((fd = getfd(console)) < 0) kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console")); if (ioctl(fd, KDGKBMODE, &mode)) { kbd_warning(errno, "ioctl KDGKBMODE"); leave(EXIT_FAILURE); } if (mode == K_UNICODE) space = "\xef\x80\xa0"; /* U+F020 (direct-to-font space) */ else space = " "; if (info) { nr = rows = cols = 0; n = getfont(fd, NULL, &nr, &rows, &cols); if (n != 0) leave(EXIT_FAILURE); if (verbose) { printf(_("Character count: %d\n"), nr); printf(_("Font width : %d\n"), rows); printf(_("Font height : %d\n"), cols); } else printf("%dx%dx%d\n", rows, cols, nr); leave(EXIT_SUCCESS); } settrivialscreenmap(); getoldunicodemap(); n = getfontsize(fd); if (verbose) printf(_("Showing %d-char font\n\n"), n); cols = ((n > 256) ? 32 : 16); nr = 64 / cols; rows = (n + cols - 1) / cols; sep = ((cols == 16) ? "%1$s%1$s" : "%1$s"); for (i = 0; i < rows; i++) { if (i % nr == 0) { lth = 0; for (k = i; k < i + nr; k++) for (j = 0; j < cols; j++) list[lth++] = k + j * rows; setnewunicodemap(list, lth); } printf("%1$s%1$s%1$s%1$s", space); for (j = 0; j < cols && i + j * rows < n; j++) { putchar(BASE + (i % nr) * cols + j); printf(sep, space); if (j % 8 == 7) printf(sep, space); } putchar('\n'); if (i % 8 == 7) putchar('\n'); fflush(stdout); } leave(EXIT_SUCCESS); return EXIT_SUCCESS; }