Fix keyboard detection from open file descriptors

If any of the file descriptors turns out to be a keyboard, we shouldn't
fail with the error that no keyboard was found.
This commit is contained in:
Kacper Słomiński 2022-06-11 15:50:55 +02:00
parent 476a0cef4a
commit 9f45079693
1 changed files with 9 additions and 1 deletions

View File

@ -280,6 +280,7 @@ static int kbd_init(void)
char *files_to_try[] = {"/dev/tty", "/dev/console", NULL}; char *files_to_try[] = {"/dev/tty", "/dev/console", NULL};
int i; int i;
int flags; int flags;
int found = 0;
/* First we need to find a file descriptor that represents the /* First we need to find a file descriptor that represents the
system's keyboard. This should be /dev/tty, /dev/console, system's keyboard. This should be /dev/tty, /dev/console,
@ -293,6 +294,7 @@ static int kbd_init(void)
/* See if this is valid for our purposes. */ /* See if this is valid for our purposes. */
if (tty_is_kbd(kb)) { if (tty_is_kbd(kb)) {
printf("Using keyboard on %s.\n", files_to_try[i]); printf("Using keyboard on %s.\n", files_to_try[i]);
found = 1;
break; break;
} }
close(kb); close(kb);
@ -303,8 +305,14 @@ static int kbd_init(void)
might point to a console. This is not especially likely. */ might point to a console. This is not especially likely. */
if (files_to_try[i] == NULL) { if (files_to_try[i] == NULL) {
for (kb = 0; kb < 3; kb++) { for (kb = 0; kb < 3; kb++) {
if (tty_is_kbd(i)) break; if (tty_is_kbd(i)) {
found = 1;
break;
} }
}
}
if (!found) {
printf("Unable to find a file descriptor associated with "\ printf("Unable to find a file descriptor associated with "\
"the keyboard.\n" \ "the keyboard.\n" \
"Perhaps you're not using a virtual terminal?\n"); "Perhaps you're not using a virtual terminal?\n");