Merge pull request #2 from qookei/master

Fix keyboard detection from open file descriptors
This commit is contained in:
Maxime Vincent 2022-06-12 11:27:23 +02:00 committed by GitHub
commit b1bf036dd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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");