13 * Get an fd for use with kbd/console ioctls.
14 * We try several things because opening /dev/console will fail
15 * if someone else used X (which does a chown on /dev/console).
19 is_a_console(int fd
) {
23 return (ioctl(fd
, KDGKBTYPE
, &arg
) == 0
24 && ((arg
== KB_101
) || (arg
== KB_84
)));
28 open_a_console(const char *fnam
) {
32 * For ioctl purposes we only need some fd and permissions
33 * do not matter. But setfont:activatemap() does a write.
35 fd
= open(fnam
, O_RDWR
);
36 if (fd
< 0 && errno
== EACCES
)
37 fd
= open(fnam
, O_WRONLY
);
38 if (fd
< 0 && errno
== EACCES
)
39 fd
= open(fnam
, O_RDONLY
);
42 if (!is_a_console(fd
)) {
49 int getfd(const char *fnam
) {
53 fd
= open_a_console(fnam
);
56 fprintf(stderr
, "Couldnt open %s\n", fnam
);
60 fd
= open_a_console("/dev/tty");
64 fd
= open_a_console("/dev/tty0");
68 fd
= open_a_console("/dev/vc/0");
72 fd
= open_a_console("/dev/console");
76 for (fd
= 0; fd
< 3; fd
++)
80 fprintf(stderr
, "Couldnt get a file descriptor referring to the console\n");
81 exit(1); /* total failure */