14 * Get an fd for use with kbd/console ioctls.
15 * We try several things because opening /dev/console will fail
16 * if someone else used X (which does a chown on /dev/console).
20 is_a_console(int fd) {
24 return (ioctl(fd, KDGKBTYPE, &arg) == 0
25 && ((arg == KB_101) || (arg == KB_84)));
29 open_a_console(char *fnam) {
32 fd = open(fnam, O_RDONLY);
33 if (fd < 0 && errno == EACCES)
34 fd = open(fnam, O_WRONLY);
37 if (!is_a_console(fd)) {
47 fd = open_a_console("/dev/tty");
51 fd = open_a_console("/dev/tty0");
55 fd = open_a_console("/dev/vc/0");
59 fd = open_a_console("/dev/console");
63 for (fd = 0; fd < 3; fd++)
68 _("Couldnt get a file descriptor referring to the console\n"));
69 exit(1); /* total failure */